# Form Tags

**URL:** <https://www.ruby-forum.com/t/form-tags/172974>\
**Category:** Rails\
**Created:** [July 30, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/form-tags/172974 "2009-07-30T18:51:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [July 30, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/form-tags/172974/1 "2009-07-30T18:51:36Z")

</div>

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 %>

```

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!

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [July 30, 2009, 7:22pm UTC](https://www.ruby-forum.com/t/form-tags/172974/2 "2009-07-30T19:22:48Z")

</div>

Hi Pete,

On Thu, 2009-07-30 at 18:51 +0200, Pete M. wrote:

> This is a total newbie question, so my apologies!

No need. Welcome aboard!

> 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.

Very common issue.

> 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

\<% end %\> is correct.

I believe your problem is that if you’re going to use  
the :controller/:action syntax, you need to enclose them in {}. e.g.,

\<%= form\_tag {:controller =\> “customer”, :action =\> “login”} %\>

You’ll want to learn to use Google as your first lines of defense 😉  
I recommend that whenever you get an error, you enter it into your  
Google search bar preceded by the word ‘rails’.

using the above as an example… Google

rails syntax error, unexpected kENSURE, expecting $end

You’ll also want to learn to read the rails documentation.

[api.rubyonrails.org](http://api.rubyonrails.org)

Focus first on the methods which are in the lower pane on the left.

> 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!

The easiest way to get a handle on some of this basic stuff is to use  
the scaffold feature. You’ll get the full stack. I recommend  
generating a rails app named ‘sandbox’. Keep it around for working out  
issues / problems later.

rails sandbox

rake db:create:all

ruby script/scaffold test\_model field1:string field2:text field3:integer

The files generated will give you the basics of the current syntax.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [July 30, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/form-tags/172974/3 "2009-07-30T19:39:25Z")

</div>

Thanks Bill,

I did try google first, but didn’t find the correct answer 🙂

OK - I tried what you said, but that seemed to give me a new problem ☹

```
<%= 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 %>

```

Error now is

syntax error, unexpected tASSOC, expecting ‘}’  
…cat(( form\_tag {:controller =\> “customer”, :action =\> "login…  
^  
/Users/pmoran/rails/r4music1/app/views/customer/\_login.html.erb:1:  
syntax error, unexpected ‘,’, expecting ‘}’  
…ag {:controller =\> “customer”, :action =\> “login”} ).to\_s); …  
^  
/Users/pmoran/rails/r4music1/app/views/customer/\_login.html.erb:9:  
syntax error, unexpected kENSURE, expecting $end

In terms of the scaffold stuff, well I also tried that and got a error  
☹

rake db:create:all  
rake aborted!  
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,  
Rakefile.rb)  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2377:in  
`raw\_load\_rakefile’  
(See full trace by running task with --trace)

And then

ruby script/scaffold test\_model field1:string field2:text  
field3:integer  
ruby: No such file or directory – script/scaffold (LoadError)

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [July 30, 2009, 8:15pm UTC](https://www.ruby-forum.com/t/form-tags/172974/4 "2009-07-30T20:15:30Z")

</div>

On Jul 30, 2009, at 12:51 PM, Pete M. wrote:

> User name: \<%= text\_field "customer", "nick" %\>
> 
> I appreciate that the end\_form\_tag has been depreciated, I tried here!

form\_tag now takes block and the 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [July 30, 2009, 8:13pm UTC](https://www.ruby-forum.com/t/form-tags/172974/5 "2009-07-30T20:13:09Z")

</div>

Hi Pete,

It looks like you have more than one problem. For starters, what  
platform are you using? OS, Ruby, Rails

ruby -v  
rails -v

On Thu, 2009-07-30 at 19:39 +0200, Pete M. wrote:

> Thanks Bill,

You’re welcome.

> ^ /Users/pmoran/rails/r4music1/app/views/customer/\_login.html.erb:9: syntax error, unexpected kENSURE, expecting $end

As a first step, try wrappiing the {…} in parens.  
form\_tag( {:controller =\> “customer”, :action =\> “login”}

If that doesn’t fix it, post the whole view file.

> In terms of the scaffold stuff, well I also tried that and got a error  
> ☹

My bad. Incomplete / incorrect instructions.

rails sandbox # this assumes you’re ok with sqlite, otherwise,  
# use -d to specify your database of choice

cd sandbox # beyond the initial step of creating your rails  
# app, all other commands must take place within  
# an app directory

rake db:create:all

# even had you been in an app directory, the command I sent

# was incorrect. use the following instead.

ruby script/generate scaffold test\_model field1:string field2:text  
field3:integer

> ruby script/scaffold test\_model field1:string field2:text  
> field3:integer  
> ruby: No such file or directory – script/scaffold (LoadError)

Both of these occurred because you weren’t in the sandbox app directory.

HTH,  
Bill
