Kindle Notes & Highlights
Read between
November 22 - November 30, 2019
else puts 'a is not 10' end
if a == 10 puts 'a is 10' elsif a == 20 puts 'a is 20' end
Arrays An array is a list of objects. Let’s play around in irb: $ irb >> a = [1,2,3,4,5]
One of the cardinal sins in the MVC model is to put too much program logic into the view.
if I have a value in the controller that I want to display in the view, then I need a mechanism for this. This is referred to as instance variable and always starts with a @.
Even with small web projects, there are often elements that appear repeatedly, for example a footer on the page with contact info or a menu. Rails gives us the option of encapsulate this HTML code in form of partials and then integrating it within a view. A partial is also stored in the directory app/views/example/. But the file name must start with an underscore (_).
<%= render "footer" %>
One of my best buddies when developing Rails applications is the Tab key. Whenever you are looking for a method for a particular problem, recreate it in the Rails console and then press the Tab key twice to list all available methods. The names of the
You can use the command rails generate to display a list of available generators: $ rails
number from 1 to 5, you can define the following helper in the file app/helpers/application_helper.rb : Listing 15. app/helpers/application_helper.rb module ApplicationHelper def render_stars(value) output = ''
ApplicationController def index @foo = 'bar' end end And