If statement based on a action


#1

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


#2

Andrew F. 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 F. removed_email_address@domain.invalid
University of Chicago - NSIT Web Services
AIM: farmerje
Jabber: removed_email_address@domain.invalid
Phone: (773)363-1058


#3

I think @controller.action_name is what you’re looking for. Haven’t
checked though…

Cheers!

-DF


#4

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


#5

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