21 February 2017

Ruby on Rails | Basic knowledge

Things you should know in Ruby on Rails:

  • Actions that you created in application controller will be available in all your controller but they are not available to views by default. 
  • To make those actions to be available to views, add this code in the same file: helper_method :action1, :action2, and so on. 
  • In Ruby, "foo".equal? "foo" will return false and :foo.equal? :foo will return true It works that way because strings in Ruby are mutable. Unlike strings, symbols(:foo) are immutable.
  • params[:foo] in @user = User.find(params[:id]) means to tell rails to get the ':foo' or ':id' from the URL of the page that user requested
  • In this case, params[:id] is 1

No comments:

Post a Comment