21 February 2017

Ruby on Rails | Syntax

Important syntax you have to know:

  • <% code %> to embed Ruby code in your HTML file. 
  • <%= code %> to generate HTML code with ruby methods. 
  • !!code to convert the code into Boolean statement.  
  • Local variable will be declared as variable and instance variable will be declared as @variable
  • Local variable only exists within its scope. Declaring variables in the controller as instance variables @variable makes them available to your view. 
  • a ||= b This operator means if 'a' is undefined then assign it the value of 'b', otherwise leave it alone.
  • @current_user ||= User.find(2) this means if @current_user is undefined, assign the value of user with user_id 2 to the @current_user otherwise perform nothing.
Please check this link for more Ruby Operators

No comments:

Post a Comment