Ruby On Rails India

As far as I know there are very few people working on RubyOnRails in India. Vinayak solutions Pvt. Ltd. is doing great in this field. Recently Manik Juneja (Director) attended the Rails conf. Landon and last week traveled Colombo to train a team of web programmers on Ruby on Rails.

October 14, 2006 at 5:22 am 31 comments

Tab completion in irb

irb has tab completion support, you need to activate this by requiring ‘irb/completion’. You can load it when you invoke irb from the command line:


% irb -r irb/completion

Or you can load the completion library when irb is running:


% irb(main):005:0> require 'irb/completion'

If you often use tab completion then:

Linux users: Can create an alias in .bashrc by following these steps:

  • % vi ~/.bashrc
  • add alias irbtc="irb -r 'irb/completion'"
  • % source ~/.bashrc

Windows Users: Can create a file named irbtc.bat in your windows\system32 folder as irb -r "irb/completion" the file content.


Now you can run irb with tab completion support by:
% irbtc

Example:

% irbtc
irb(main):001:0> st="this is a string"
=> "this is a string"
irb(main):002:0> st.len
tab
irb(main):002:0> st.length
=> 16
irb(main):003:0> st.up
tabtab
st.upcase st.upcase! st.upto
irb(main):003:0> st.up

October 7, 2006 at 7:59 am 8 comments

What do you see a face or an Eskimo?

eskimo.jpg

September 28, 2006 at 7:15 am 11 comments

Lib file state_select.rb

If you are not interested in installing a plugin just for one method(state_select) then You can put state_select.rb file in you rails lib directory. And include state_select.rb file in your controller where ever you want to use state_select method.

The url for state_select.rb is http://opensvn.csie.org/state_select/trunk/lib/state_select.rb
Feedback please….

September 13, 2006 at 6:42 am 5 comments

Plugin: state_select, generate drop down selection box for states

I have wrote my first plugin(state_select). This plugin allows to create drop down list for states, same as country_select method in rails. I know this is not a big deal…

Curently it can generate state list for India, US, Canada, Australia and Spain(default is US).

Usage:

  • state_select(object, method, country='US', options = {}, html_options = {})

Return select and option tags for the given object and method, using state_options_for_select to generate the list of option tags.

  • state_options_for_select(selected = nil, country = 'US')

Returns a string of option tags for states in a country. Supply a state name as selected to have it marked as the selected option tag.

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

The svn repository can be found at http://opensvn.csie.org/state_select/trunk/

Install plugin by

script/plugin install http://opensvn.csie.org/state_select/trunk/

September 12, 2006 at 2:34 pm 15 comments

12 Balls Problem

You have 12 balls (of any kind), one ball either lighter or heavier than the other 11. A scale is provided to you but only three weighs are allowed. How can you possibly figure out which is the odd ball?

September 8, 2006 at 10:07 am 7 comments

Deprecated Finders in Rails 1.1.5

These Finders are deprecated

  • find_first [use find(:first)]
  • find_all [use find(:all)]
  • find_on_conditions [use find(:conditions)]

August 23, 2006 at 12:40 pm Leave a comment

Ajax pagination links: Create pagination links with link_to_remote

Here is a method by mixonix to create pagination links by link_to_remote. Copy this code in your helpers/application_helper.rb


def ajax_pagination_links(paginator, options={})

options.merge!(ActionView::Helpers::PaginationHelper::DEFAULT_OPTIONS) {|key, old, new| old}
  window_pages = paginator.current.window(options[:window_size]).pages
  return if window_pages.length <= 1 unless
         options[:link_to_current_page]

first, last = paginator.first, paginator.last

returning html = '' do
    if options[:always_show_anchors] and not window_pages[0].first?
      html << link_to_remote(first.number, :update => options[:update], :url => { options[:name] => first }.update(options[:params] ))
      html << ' ... ' if window_pages[0].number - first.number > 1
      html << ' '
    end

window_pages.each do |page|
      if paginator.current == page && !options[:link_to_current_page]
        html << page.number.to_s
      else
        html << link_to_remote(page.number, :update => options[:update], :url => { options[:name] => page }.update(options[:params] ))
      end
      html << ' '
    end

if options[:always_show_anchors] && !window_pages.last.last?
      html << ' ... ' if last.number - window_pages[-1].number > 1
      html << link_to_remote(paginator.last.number, :update => options[:update], :url => { options[:name] => last }.update( options[:params]))
    end
  end
end

and use following code for creating links


        <%= ajax_pagination_links @pages, {:params => {:search_query => @params[:search_query]} } %>

August 16, 2006 at 3:35 pm 7 comments

Tab Problem in rails .rhtml files

The situation was: running Ruby 1.8.4, Rails 1.1.2, on WinXP & WEBrick server.

My application was working fine, but as I installed Rmagick my application crashed.
I got strange errors like:

compile error /script/../config/../app/views/layouts/application.rhtml:18: parse error, unexpected $, expecting kEND

if I refresh again the error actually changes(further refreshes flip back & forth between errors):

compile error

/script/../config/../app/views/layouts/application.rhtml:18: Invalid char `01′ in expression

./script/../config/../app/views/layouts/application.rhtml:19: parse error, unexpected tCONSTANT, expecting kEND

./script/../config/../app/views/layouts/application.rhtml:20: parse error, unexpected tCONSTANT, expecting kEND

./script/../config/../app/views/layouts/application.rhtml:21: Invalid char `06′ in expression

./script/../config/../app/views/layouts/application.rhtml:21: parse error, unexpected $, expecting kEND

Then my colleagues told me the root of this problem, this was because of tabs in .rhtml files. Also they told me the simple solution:

Put template = template.gsub(/\t/, ” “)  in your

\vendor\rails\actionpack\lib\action_view\base.rb file at line 496 as very first line of def compile_template
Restart webserver and you are done….

August 10, 2006 at 2:51 pm 6 comments

converting all newline characters to br tag

I was surprised as there is no function in ruby to convert all newline characters to <br>.

Here is a php nl2br equivalent method to convert all newline characters (\n) to break tag (<br>) in a string.

 def nl2br(s)
     s.gsub(/\n/, '<br>')
 end

August 7, 2006 at 10:48 am 15 comments

Older Posts Newer Posts


Important Notice…

I have moved this blog to http://webonrails.com . I will continue posting at http://webonrails.com, not on https://webonrails.wordpress.com.

Kindly update your book marks to http://webonrails.com

and http://webonrails.com/feed .

I am really very sorry for inconvenience.

Comming Soon….

Domain for Sale

TheRailsHosting.com


(Contact me)

Calender

November 2021
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Subscribe

  • Add to Google
  • Subscribe in NewsGator Online
  • Subscribe with Bloglines
  • WebOnRails on feedburner
  • technorati

del.icio.us

Feeds

Flickr Photos

Visitor’s Location

Blog Stats

  • 18,420 hits