Ruby on Rails

View Helpers

#create a link to controller 'categories' at action 'list'
link_to "text of link", :controller => 'categories', :action => 'list'

image_tag "spinner.png", :class => "image", :alt => "Spinner"

stylesheet_link_tak "scaffold", "admin", :media => "all"

#Forms
<%
form_for :person, @person, :url => {:action => "update"},
  :html => {:id => 'person_form'} do |f|
%>

First name: <%= f.text_field :first_name %>
Age: <%= f.text_field :age, :size => 2 %>
Bio: <%= f.text_area :biography %>

<% end %>

#To insert a text field
text_field :modelname, :attribute_name, options
password_field....
file_field
text_area

#this
radio_button "model", "category", "rails"
#turns into this
<input type="radio" id="post_category" name="post[category]" value="rails"
   checked="checked"/>


check_box "post", "validated" #post.validated? return 1 or 0
#turns into
<input type="checkbox" id="post_validate" name="post[validated]"
       value="1" checked="checked"/>
<input name="post[validated]" type="hidden" value="0"/>

   

select "post", "person_id", Person.find_all.collect {|p| [p.name, p.id]},
    {:include_blank => true}
#turns into
<select name="post[person_id]">
  <option></option>
  <option value="1" selected="selected">David</option>
  <option value="2">Sam</option>
  <option value="3">Tobias</option>
</select>


José M. Vidal .

11 of 16