Showing posts with label rubyonrails. Show all posts
Showing posts with label rubyonrails. Show all posts

[Ruby On Rails] Get the variable type in ruby on rails

is_a()

addr = Array.new
addr.is_a?Array #returns true
Continue Reading

RUBY: Easy to create first controller in ruby on rails

Create new controller in ruby on rails is the easy thing. Just follow the following process

[root]# script/generate controller <controller-name>

Sample
script/generate controller registration

this will genereate the following folders/files.

      exists  app/controllers/
      exists  app/helpers/
      create  app/views/registration
      exists  test/functional/
      create  app/controllers/registration_controller.rb
      create  test/functional/registration_controller_test.rb
      create  app/helpers/registration_helper.rb
Continue Reading

RUBY: slice() - ruby on rails

Slicing the string or characters from the given start position with the given length of characters.

Look at the qucik example:

        dob = '10/13/1986'
        dob_mm = dob.slice(0,2)  #this returns 10
        dob_dd = dob.slice(2,2) #this returns 13
        dob_yy = dob.slice(4,4) #this returns 1986
Continue Reading

RUBY: Ruby on Rails - string replace

gsub

gsub() is the always very useful function in ruby.

Syntax:
string.gsub("<search char>","<replace Char>")
        string.gsub(/'/,"") #replce/remove single quotes from the string


You should be careful that the string variable should not have a nil value. Otherwise it will rise a nil exception. 


Continue Reading