Doubt on form_tag do

Hi all,
i’m a nuby on rails. I’m using patrick Lenz’s book to study rails. When
creating the login page for th application i got a problem.
given below is the code

<% form_tag do %>

Please log in.



Username:
<%= text_field_tag ‘login’%>



Password:
<%= password_field_tag ‘password’ %>


<%= submit_tag ‘login’ %>


<% end_form %>

But when browsing to the page I get the error

Showing app/views/account/login.rhtml where line #13 raised:
compile error
D:/TECHNO~1/INSTAN~1/rails_apps/shovell/config/…/app/views/account/login.rhtml:13:
parse error, unexpected $, expecting kEND

But when I change the code from <% end_form %> to <% end %>
the page loads but no textboxes are shown.

I tried checking my code and the format seems to be right as in the
book, I also googled to check if anything is wrong, but couldn’t come up
with a solution. So I believe someone from here can help me out.
Thanks.
Chris

<% form_tag do %>

Please log in.



Username:
<%= text_field_tag ‘login’%>



Password:
<%= password_field_tag ‘password’ %>


<%= submit_tag ‘login’ %>

<% end_form %> – Here is the error. Repleace “end_form” by “end”

Regards.

Nicolas Santa.

I’m Sorry, i’m restart the message.

You syntaxis are right. So you must have another error. Check the
installation of rails.

Nicolás Santa.

You aren’t passing an action for the form…

<% form_tag ‘/controller/action’ do %>

Replace “/controller/action” with the actual controller and action
that will process the form data. I don’t know why that would cause
the text boxes not to show up, but it’s still something that needs to
be fixed. Try it and see if that clears up the problem.

On Jun 26, 7:57 am, Christy J. [email protected]

Thanks Nicolás,
though, i’m not sure. it may be an issue with my rails version. The
<% start_form_tag %> is working

Chris

try putting an = sign within the <% … %> —> <%= … %> to allow
what is enclosed to be rendered out. There is some inconsistency
between form tag functions which can throw me for a loop too.

On Jun 26, 8:32 am, “[email protected]

I think your problem is versions of rails.

I found with the older version of rails that I was running I had
similar problems.

With Version 1.2 the accepted syntax is
<%form_tag do%>
blah blah
<%end%>

With older versions you may have more luck with:
<%=form_tag %>
blah blah
<%= form_tag_end %>

At least that is what I have scribbled in the margin of my
AgileDevWithRails book.

Not sure if the = is required though.

Hope that helps
George

On Jun 27, 3:26 pm, Christy J. [email protected]

[email protected] wrote:

You aren’t passing an action for the form…

<% form_tag ‘/controller/action’ do %>

Replace “/controller/action” with the actual controller and action
that will process the form data. I don’t know why that would cause
the text boxes not to show up, but it’s still something that needs to
be fixed. Try it and see if that clears up the problem.

On Jun 26, 7:57 am, Christy J. [email protected]

Hi Andrew,
It’s not helping. still getting a
D:/TECHNO~1/INSTAN~1/rails_apps/shovell/app/controllers/account_controller.rb:15:
parse error, unexpected $, expecting kEND

Any way thanks for looking at the matter.
Chris

Thanks to all for the help. I rewrote the whole code and now it’s
working.
I changed my login.rhtml to

<%= start_form_tag :action => ‘login’ %>

Please log in.

Username: <%= text_field :user, :login %>

Password: <%= password_field :user, :password %>

<%= submit_tag 'login'%>

<%= end_form_tag %> ------------------------------------

and my login method in the account controller to

def login
if request.post?
@current_user = User.find(:first, :conditions => [“login = ? and
password = ?”,
params[:user][:login],params[:user][:password]])
unless @current_user.nil?
session[:user_id] = @current_user.id
redirect_to :controller => ‘story’
end
end
end

and it’s working. So it must be domething with my rails version.
Anyway thanks for the help. You all are a very helpful bunch
Chris

Christy,

Do be careful with this as start_form_tag and end_form_tag have been
depreciated and will be removed from rails 2.0 So if you are
currently using an older 1.x version of Rails without support for
form_tag and then at some point you (or even worse the system admins,
if you don’t own your own box) upgrade rails, suddenly your
application may break. If none of the features/fixes in the current
versions of Rails make any difference to you, you might want to
consider freezing rails for your application. See
http://www.paulsturgess.co.uk/articles/show/18-why-you-should-freeze-rails-on-a-shared-host-environment
for more info on freezing rails.

On Jun 27, 5:16 am, Christy J. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs