On Jul 30, 2009, at 12:51 PM, Pete Moran wrote:
> This is a total newbie question, so my apologies!
>
> I am learning Ruby from the book Ruby for rails - the only issue is
> the
> examples seem to have been written in a earlier version of Ruby.
>
> The code in question is
>
> <%= form_tag :controller => "customer",
> :action => "login" %>
> <p>User name: <%= text_field "customer", "nick" %></p>
> <p>Password: <%= password_field "customer", "password" %></p>
> <p><input type="Submit", value="Log in"/></p>
> <% end_form_tag %>
> </p>
>
> Which gives the error
>
> undefined local variable or method `end_form_tag' for
> #<ActionView::Base:0x1c39e38>
>
> I appreciate that the end_form_tag has been depreciated, I tried
> replacing it with <% end %>
>
> Which then gives
>
> compile error
> /Users/pmoran/rails/r4music1/app/views/customer/_login.html.erb:9:
> syntax error, unexpected kENSURE, expecting $end
>
> I can't see any examples on the documentation which also specify the
> controller, as I say I am a total Ruby newbie so please go easy on me
> here!
form_tag now takes block and the </form> tag is implicit
<% form_tag :controller => "customer",
:action => "login" do |form| %>
<p>User name: <%= text_field "customer", "nick" %></p>
<p>Password: <%= password_field "customer", "password" %></p>
<p><input type="Submit", value="Log in"/></p>
<% end %>
Note that the form_tag is in <% %> rather than <%= %>
The <% end %> is for the block that is started by the 'do'.
It also looks like you may have a Customer model and if that is the
case, then you probably want something like (assuming you have tucked
it into an instance variable with '@customer = Customer.new' in your
controller):
<% form_for @customer, :url => { :controller => "customer",
:action => "login" } do |form| %>
<p><%= form.label :nick, "User name:" %>
<%= form.text_field :nick %></p>
<p><%= form.label :password, "Password:" %>
<%= form.password_field :password %></p>
<p><%= submit_tag "Log in" %></p>
<% end %>
-Rob
Rob Biedenharn http://agileconsultingllc.com
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---