<ol> <li>Line 1<br /></li> <li>Line 2<br /></li> <li>Line 3</li> </ol>Ans: The output is
<ol> <li>Line 1<br /> </li> <li>Line 2<br /> </li> <li>Line 3</li> </ol>
ol { list-style-type: upper-roman; }
# Problem 2a. (1..3).each do |i| (1..3).each do |j| print "*" end end print "\n" Ans: ********* # Problem 2b. (1..3).each do |i| (1..3).each do |j| print "*" print "\n" end end Ans: * * * * * * * * * # Problem 2c. (1..3).each do |i| (1..3).each do |j| print "*" end print "\n" end Ans: *** *** ***
s = ["cat", "dog", "mouse"] t = "" s.each do |x| t = x + t end print t, "\n" Ans: mousedogcat
-------------- input.html.erb View Code -------------------- <% form_tag "receipt" %> <%= text_field_tag :last_name, "" %> <%= text-field-tag :first name, "" > <%= text_field_tag : item, "" > <%= text_field_tag :price, '' %> <%= end %> -------------- purchase_controller.rb Controller Code ------ function purchase first name = params(:first name) end -------------- receipt.html.erb View Code ------------------ <h2>Receipt<h1> <p>"Thankyou" + <%= first name %> + "for your purchase.</p> ------------------------------------------------------------ Corrected Version: -------------- input.html.erb View Code -------------------- <%= form_tag "receipt" %> <%= text_field_tag :last_name, "" %> <%= text_field_tag :first_name, "" %> <%= text_field_tag :item, "" %> <%= text_field_tag :price, '' %> <% end %> -------------- purchase_controller.rb Controller Code ------ def purchase @first_name = params[:first_name] end -------------- receipt.html.erb View Code ------------------ <h2>Receipt<h2> <p>Thankyou <%= @first_name %> for your purchase.</p> ------------------------------------------------------------
body { background-color: rgb(217, 58, 13); } Ans: body { background-color: #d93a0d; }
<% form_tag 'show' do %> ... Controls go here. <% end %>
<% form_for @item, :url => { :action => 'show' } do |f| %> ... Controls go here. <% end %>or shorter:
<% form_for @item, 'show' do |f| %> ... Controls go here. <% end %>
<%= text_field_tag :celsius, '20', :class => 'tf' %>:celsius is the name; '20' is the initial value.
<%= f.text_field :celsius, :class => 'tf' %>:celsius is the field of the database object f.
<%= select_tag :source_rate, options_for_select([['Dollars', 1.00000], ['Euro', 1.36749], ['Pesos', 12.6149], ['Pounds', 1.58228]]), :class => 'ddm' %>:source_rate is the name; the first column of the array are the values displayed in the dropdown menu; the second column are the values returned to the controller to be read by a params statement. the option tags are the HTML option tags.
<%= f.select :source_rate, [['Dollars', 1.00000], ['Euro', 1.36749], ['Pesos', 12.6149], ['Pounds', 1.58228]], :class => 'ddm' %>:source_rate is the field of the database object f; the values of the dropdown menu are specified in the array as they were in the FormTagHelper version; note that for the FormHelper version, no options_for_select method is needed.
<%= radio_button_tag :group, value, true %>:group sets the button group (in a group of radio buttons, only can be checked at a time)
<%= f.radio_button :group, value, :checked => true %>:group sets the button group (in a group of radio buttons, only can be checked at a time)
<%= check_box_tag :sugar, 1, true, :class => 'cb' %>:sugar is the name of the checkbox
<%= f.check_box :sugar, 1, :checked => true, :class => 'cb' %>:sugar is the name of the checkbox