Question for you all is it possible to use an action in an if statement? I am using the same form for edit and new and I have a cancel button on the page. This cancel button is built with an if statement that looks right now to see if a parameter exists to define where to go back to if the user cancel. The problem occurs when the user submits the form and there are missing fields by validation. The form is redrawn but my parameter is now gone so it assumes that I was editing on the cancel as opposed to going back to my list page. When the user clicks on the button they get an error because there is no id for my object to show as it does not exist. basically can you do something like this: <% if :action == ''create'' %> go back to the list <% else %> go to show something <% end %> and if you can what is the correct syntax as that does not work (already tried it) thanks again for all your help Just trying to clean up my last few bugs/issues before the release of this app to beta at the beginning of the week. Andrew
Andrew Filipowski wrote:> Question for you all is it possible to use an action in an if > statement? I am using the same form for edit and new and I have a > cancel button on the page.You want to make your form a partial and then in the ''edit'' and ''new'' actions use views which wrap whatever is necessary around a call to render_partial. See http://rails.rubyonrails.com/classes/ActionView/Partials.html -- Jesse Farmer <farmerje@uchicago.edu> University of Chicago - NSIT Web Services AIM: farmerje Jabber: farmerje@im.uchicago.edu Phone: (773)363-1058
I _think_ @controller.action_name is what you''re looking for. Haven''t checked though... Cheers! -DF On 1/12/06, Andrew Filipowski <a.filipowski@mac.com> wrote:> Question for you all is it possible to use an action in an if > statement? I am using the same form for edit and new and I have a > cancel button on the page. > > This cancel button is built with an if statement that looks right now > to see if a parameter exists to define where to go back to if the > user cancel. The problem occurs when the user submits the form and > there are missing fields by validation. The form is redrawn but my > parameter is now gone so it assumes that I was editing on the cancel > as opposed to going back to my list page. When the user clicks on the > button they get an error because there is no id for my object to show > as it does not exist. > > basically can you do something like this: > > <% if :action == ''create'' %> > go back to the list > <% else %> > go to show something > <% end %> > > and if you can what is the correct syntax as that does not work > (already tried it) > > thanks again for all your help > > Just trying to clean up my last few bugs/issues before the release of > this app to beta at the beginning of the week. > > Andrew > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
David Felstead wrote:> I _think_ @controller.action_name is what you''re looking for. Haven''t > checked though... > > Cheers! > > -DFPretty sure it''s ''controller.action_name''. There is also a ''controller.controller_name''. _Kevin -- Posted via http://www.ruby-forum.com/.
Thanks all I''ll try this last one. I am using partials to build my form but you can come at edit from two different places and I wanted to bring the user back to where they came from if they clicked cancel. I did get this to work: current_page?(:controller => ''name'', :action => ''create'') == true I found that the only place the link was breaking was on the create because i was passing my own param list => true from the home page in order to get users to come back. However this last suggestion seems to be a little simplier and nicer. Thank what i found and how I was doing it before. Andrew On Jan 12, 2006, at 1:21 AM, Kevin Olbrich wrote:> David Felstead wrote: >> I _think_ @controller.action_name is what you''re looking for. >> Haven''t >> checked though... >> >> Cheers! >> >> -DF > > Pretty sure it''s ''controller.action_name''. There is also a > ''controller.controller_name''. > > _Kevin > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails