Passing value through render :action

Hi, I was wondering if there was any way to pass a value through the
render :action in my controller. The controller calls render when fields
are left blank in my form and errors need to be shown. With redirect_to
:action, I am simply able to add a parameter to be passed like so:

redirect_to :action => ‘new’, :parameter => @form.pass_this_value

However I am not able to do the same with render :action. I cannot use
redirect_to since it does not display the form field errors. Is there
any way around this? Or another means of retrieving a value once a view
has been rendered? Thanks.

-Gilles

Try:

render :action => ‘new’, :locals => { :parameter =>
@form.pass_this_value }

Jason

I tried your suggestion, Jason. I still am not getting anything passed.
Maybe theres something I’m missing.

-Gilles

Jason R. wrote:

Try:

render :action => ‘new’, :locals => { :parameter =>
@form.pass_this_value }

Jason

However I am not able to do the same with render :action. I cannot use
redirect_to since it does not display the form field errors. Is there
any way around this? Or another means of retrieving a value once a view
has been rendered? Thanks.

Make the parameters you want available within an instance variable.

@parameter = @form.pass_this_value

or just access @form.pass_this_value from your view.

There is one value that I want to pass along so I can access it in the
‘new’ view after the render :action has been carried out in ‘create’. I
pass along this value from ‘new’ to ‘create’ through a hidden form
field, but I am unable to pass it back to ‘new’ from ‘create’ using the
render :action.

If you pass a form variable (hidden or not) by submitting to the create
method, then that variable will be available from params[:my_variable].
You can access params[:my_variable] from your ‘new’ view if ‘new’ is
rendered from create.

If you’re still having trouble, providing some code here would help
others troubleshoot what you’re trying to do.

The parameter is not accessible from my view. The function in the
controller does not correspond with anything in the view. I have the
‘create’ function that gets called when a form is submitted from the
‘new’ function which has a corresponding ‘new’ view. So the form in the
‘new’ view is calling ‘create’, then finds that some or all of the form
fields are not correctly filled out in ‘create’. At this time it renders
:action ‘new’ to display the ‘new’ view with the errors displayed along
with it.

There is one value that I want to pass along so I can access it in the
‘new’ view after the render :action has been carried out in ‘create’. I
pass along this value from ‘new’ to ‘create’ through a hidden form
field, but I am unable to pass it back to ‘new’ from ‘create’ using the
render :action.

I am currently using this value to differentiate the view of ‘new’
according to the value. So ‘new’ would look differently based on the
parameter. I hope all of this makes sense. Is there a way to implement
this?

-Gilles

Curtis S. wrote:

Make the parameters you want available within an instance variable.

@parameter = @form.pass_this_value

or just access @form.pass_this_value from your view.