What is the Rails3 equivalent for start_form_tag?

Newbie here ... I'm just worried that, clearly, an old rail book.

To create the form, they have the following code:

<%= start_form_tag(:action => 'create')%>

        <%= text_field(:album, :title) %><br />
        <%= text_field(:album, :artist) %><br />
        <%= text_field(:album, :genre) %><br />
        <%= datetime_select(:album, :release_date) %><br />

        <%= submit_tag("Create") %>

    <%= end_form_tag %> 

What is the correct Rails3 syntax for this code?

Thank.

+5
source share
3 answers

Quite a lot has changed since Rails 1, and I was really impressed by the people who are willing to spend time to sit down with Rails 3 and learn the differences (1). The community should welcome them and RTFM's are not helping. Here I think I can help.

I would write this in Rails 3:

<%= form_for(@album) do |f| %>
  <p>
    <%= f.label :title %>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :artist %>
    <%= f.text_field :artist %>
  </p>

  <p>
    <%= f.label :genre %>
    <%= f.text_field :genre %>
  </p>

  <p>
    <%= f.label :release_date %>
    <%= f.datetime_select :release_date %>
  </p>

  <%= f.submit %>
<% end %>

Woah, so many changes! Where to begin? Top line, of course!

form_for - , Rails . @album, , , : 1) 2) .

, , app/views/albums/new.html.erb :

<h2>New Album</h2>
<%= render "form" %>

OMG, ! : render "form" /views/albums/ _form.html.erb. , form_for . ? .

AlbumsController new - :

def new
  @album = Album.new
end

form_for , : ", Album, , , create , Rails", , .

:

, albums_path. ?

Ruby on Rails 2 RESTful . , , , . : RESTful - URL- , , , POST ( , ?) /, create.

Rails ?

config/routes.rb :

resources :albums

"" (, , , , ). , , .

, form_for. , /albums , . , f? , Album new ( , edit). :

<%= f.text_field :title %>

Rails 1:

<%= text_field :album, :title %>

, Rails , .

, , . , :title, Title. :release_date " ". .

f.submit. , " ", @album - , " ", . ?

edit!

def edit
  @album = Album.find(params[:id]
end

app/views/albums/edit.html.erb , new.html.erb sibling:

<h2>Editing Album</h2>
<%= render "form" %>

, -, ( ).

edit, , /albums/1 Rails-speciality PUT . , , .

, , , , , .

3 .

(1) , , .

+21

, RAILS Stuff!!!

, ... Rails 3!!!

, BBonifield, form_tag

+2

Why don't you try the Micheal Hartl Rails Tutorial , this is probably one of the best guides to get started with Rails, RailsCasts.com is pretty cool too.

0
source

All Articles