I''ve got a form that should post to user/login. The code to start the tag is: <%= start_form_tag { :controller => "user", :action => "login" } %> That gives me this exception: compile error script/../config/../app/views/user/login.rhtml:1: parse error, unexpected tASSOC, expecting ''}'' _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", :action => "login" } ).to_s); _erbout.concat "\n" ^ script/../config/../app/views/user/login.rhtml:1: parse error, unexpected '','', expecting ''}'' _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", :action => "login" } ).to_s); _erbout.concat "\n" However if I do: <%= start_form_tag({ :controller => "user", :action => "login" }) %> it just spits out a form <form action="/"> Not sure what''s going on..I need to be able to specify the controller and action that the form posts to. Pat
Jonathan Viney
2006-Jan-19 12:25 UTC
[Rails] Re: start_form_tag not taking url_for options
My guess would be that the first example is giving an error because it thinks you are passing a code block, not a hash, and the code block has syntax errors. This should work: <%= form_tag :controller => ''user'', :action => ''login'' %> Cheers, Jonathan. Pat Maddox wrote:> I''ve got a form that should post to user/login. The code to start the > tag is: > <%= start_form_tag { :controller => "user", :action => "login" } %> > > That gives me this exception: > compile error > script/../config/../app/views/user/login.rhtml:1: parse error, > unexpected tASSOC, expecting ''}'' > _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", > :action => "login" } ).to_s); _erbout.concat "\n" > ^ > script/../config/../app/views/user/login.rhtml:1: parse error, > unexpected '','', expecting ''}'' > _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", > :action => "login" } ).to_s); _erbout.concat "\n" > > > > However if I do: > <%= start_form_tag({ :controller => "user", :action => "login" }) %> > > it just spits out a form <form action="/"> > > Not sure what''s going on..I need to be able to specify the controller > and action that the form posts to. > > Pat-- Posted via http://www.ruby-forum.com/.
When I do that, it''s still generating the wrong form tag: <form action="/" method="post"> On 1/19/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> My guess would be that the first example is giving an error because it > thinks you are passing a code block, not a hash, and the code block has > syntax errors. > > This should work: > > <%= form_tag :controller => ''user'', :action => ''login'' %> > > Cheers, Jonathan. > > Pat Maddox wrote: > > I''ve got a form that should post to user/login. The code to start the > > tag is: > > <%= start_form_tag { :controller => "user", :action => "login" } %> > > > > That gives me this exception: > > compile error > > script/../config/../app/views/user/login.rhtml:1: parse error, > > unexpected tASSOC, expecting ''}'' > > _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", > > :action => "login" } ).to_s); _erbout.concat "\n" > > ^ > > script/../config/../app/views/user/login.rhtml:1: parse error, > > unexpected '','', expecting ''}'' > > _erbout = ''''; _erbout.concat(( start_form_tag { :controller => "user", > > :action => "login" } ).to_s); _erbout.concat "\n" > > > > > > > > However if I do: > > <%= start_form_tag({ :controller => "user", :action => "login" }) %> > > > > it just spits out a form <form action="/"> > > > > Not sure what''s going on..I need to be able to specify the controller > > and action that the form posts to. > > > > Pat > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Kevin Olbrich
2006-Jan-19 12:37 UTC
[Rails] Re: Re: start_form_tag not taking url_for options
Pat Maddox wrote:> When I do that, it''s still generating the wrong form tag: > <form action="/" method="post">What do you get if you just stick in a url_for :controller=>''user'', :action=>''login'' ? _Kevin -- Posted via http://www.ruby-forum.com/.
Pat Maddox
2006-Jan-19 12:43 UTC
[Rails] Re: Re: start_form_tag not taking url_for options
On 1/19/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote:> Pat Maddox wrote: > > When I do that, it''s still generating the wrong form tag: > > <form action="/" method="post"> > > What do you get if you just stick in a > > url_for :controller=>''user'', :action=>''login'' > > ? > > _Kevin > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >I just tried: <form action="<%= url_for :controller=>''user'', :action=>''login'' %>" method="post"> instead of using start_form_tag, and I get the same thing still..I wonder if webrick might be caching it or something? I''ve cleared the cache on my browser multiple times, used a different browser, and even tried connecting from a different computer. I haven''t turned any caching on in rails, so unless it''s on by default somewhere, I don''t know why anything would be cached. Pat
Pat Maddox
2006-Jan-19 12:53 UTC
[Rails] Re: Re: start_form_tag not taking url_for options
On 1/19/06, Pat Maddox <pergesu@gmail.com> wrote:> On 1/19/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote: > > Pat Maddox wrote: > > > When I do that, it''s still generating the wrong form tag: > > > <form action="/" method="post"> > > > > What do you get if you just stick in a > > > > url_for :controller=>''user'', :action=>''login'' > > > > ? > > > > _Kevin > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > I just tried: > <form action="<%= url_for :controller=>''user'', :action=>''login'' %>" > method="post"> > > instead of using start_form_tag, and I get the same thing still..I > wonder if webrick might be caching it or something? I''ve cleared the > cache on my browser multiple times, used a different browser, and even > tried connecting from a different computer. I haven''t turned any > caching on in rails, so unless it''s on by default somewhere, I don''t > know why anything would be cached. > > Pat >Okay I might be getting a little bit closer... url_for :controller => ''user'', :action => ''login'' apparently returns ''/'' If I change the controller to anything else, I get the expected url. If I change the action to anything else, I get the expected url. Just can''t use this combo, apparently. Now I think I''ve really figured it out..in my routes.rb file I have: map.connect '''', :controller => "user", :action => "login" So I guess url_for uses routes to generate the urls? Not sure..is there any way I can make user/login respond to the app root, and still be able to use url_for in other places? Pat
> I just tried: > <form action="<%= url_for :controller=>''user'', :action=>''login'' %>" > method="post"> > > instead of using start_form_tag, and I get the same thing still..I > wonder if webrick might be caching it or something?To ease your fears, try adding ''id="something"'' to your form declaration - if you see that in the source reaching the browser, you know nothing is being cached anywhere down the chain. Assuming caching isn''t the issue, what url do you expect to get? Have you changed routing.rb to map / to user/login? Tom
Pat Maddox
2006-Jan-19 12:58 UTC
[Rails] Re: Re: start_form_tag not taking url_for options
> Assuming caching isn''t the issue, what url do you expect to get? Have > you changed routing.rb to map / to user/login?Yeah, I did..is that what''s causing this? I''m kind of guessing so, but I didn''t know that url_for uses routes to generate the urls. It seems as if I map / after the default route, everything works fine: # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' map.connect '''', :controller => "user", :action => "login" Does that sound right to you? Pat
Jarkko Laine
2006-Jan-19 13:01 UTC
[Rails] Re: Re: start_form_tag not taking url_for options
On 19.1.2006, at 14.53, Pat Maddox wrote:> Okay I might be getting a little bit closer... > url_for :controller => ''user'', :action => ''login'' apparently > returns ''/'' > > If I change the controller to anything else, I get the expected url. > If I change the action to anything else, I get the expected url. Just > can''t use this combo, apparently. > > Now I think I''ve really figured it out..in my routes.rb file I have: > map.connect '''', :controller => "user", :action => "login" > > So I guess url_for uses routes to generate the urls?Most definitely, that''s the (half of) idea behind routing and using these url helpers. They will change according to your needs. However, url_for will use the first route that matches, so you can put this above the route you mention: map.connect ''user/login'', :controller => "user", :action => "login" That way, both url''s map to the same controller but the url generation in Rails uses the user/login one. //jarkko> Not sure..is > there any way I can make user/login respond to the app root, and still > be able to use url_for in other places? > > Pat > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi
On 1/19/06, Pat Maddox <pergesu@gmail.com> wrote:> > Assuming caching isn''t the issue, what url do you expect to get? Have > > you changed routing.rb to map / to user/login?> Yeah, I did..is that what''s causing this? I''m kind of guessing so, > but I didn''t know that url_for uses routes to generate the urls. It > seems as if I map / after the default route, everything works fine:url_for does use routes to generate urls. this gives you loads of flexibility when changing your url schemes, assuming you''ve used url_for throughout your app.> # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > map.connect '''', :controller => "user", :action => "login"Looks good Tom -- email : tom at popdog.net