Pass instance variable from one method to another controller

Hi Everybody!

I m back.
I have a non-model form (I am using active_record_no_table gem for
validations). When the user fills that form and submits it, I want to
process the form and then display it back to the user just like the
"show" method in a scaffold.

Now, since this is a non-model form, I need to pass the instance
variable from "create" method to "show" method.

I know that rather than redirecting to show method, I can display data
back to the user using a partial and passing a locals hash to the
partial.
But I don't want to do this. The reason is there is a link on the "show"
view that allows the user to print the show view in PDF format and I
want to do the same with the link...passing the local variable to the
show action.

How can I do this?

Please advise?

Many Thanks!

Rails Learner wrote:

Hi Everybody!

I m back.
I have a non-model form (I am using active_record_no_table gem for
validations). When the user fills that form and submits it, I want to
process the form and then display it back to the user just like the
"show" method in a scaffold.

Now, since this is a non-model form, I need to pass the instance
variable from "create" method to "show" method.

I know that rather than redirecting to show method, I can display data
back to the user using a partial and passing a locals hash to the
partial.
But I don't want to do this. The reason is there is a link on the "show"
view that allows the user to print the show view in PDF format and I
want to do the same with the link...passing the local variable to the
show action.

How can I do this?

Put in a link_to parameter. Remember that link_to can take more options
than :controller and :action.

Please advise?

Many Thanks!

Best,

Hi Marnen,

How can I pass the the whole object in link_to?

For instance, if I have a child object with first_name and last_name as
attributes, then I need to pass the child object as a hash.

Right now, what is working for me is this:
<%= link_to 'Create PDF', { :controller => 'children', :action =>
'show', :format => :pdf, :first_name => @child.first_name, :last_name =>
@child.last_name } %>

And, I want to do something like this (but it's not working):
<%= link_to 'Create PDF', { :controller => 'children', :action =>
'show', :format => :pdf, :child => @child } %>

Rails Learner wrote:

Hi Marnen,

How can I pass the the whole object in link_to?

You can't.

For instance, if I have a child object with first_name and last_name as
attributes, then I need to pass the child object as a hash.

No. Pass them as two separate parameters (as I guess you're currently
doing), munge them together into one string (not recommended), or pass
an object ID if you can query the DB for it.

Hi Marnen,

Thanks for confirming that.
Many Thanks!