# How to get value from view?

**URL:** <https://www.ruby-forum.com/t/how-to-get-value-from-view/169753>\
**Category:** Rails\
**Created:** [June 8, 2009, 11:05am UTC](https://www.ruby-forum.com/t/how-to-get-value-from-view/169753 "2009-06-08T11:05:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [June 8, 2009, 11:05am UTC](https://www.ruby-forum.com/t/how-to-get-value-from-view/169753/1 "2009-06-08T11:05:33Z")

</div>

Hello all,

I have following problem,

I have a view called “new\_sub\_type.html.haml” and controller  
“SubscriptionTypes”. In this view i’m showing a dropdown list of  
subscription types.

When user submit form, I show another view “new\_credit\_card.html.haml”  
which is in controller “CreditCards”. This form is submitted to  
“SubscriptionTypes” controller.

Then i validate credit card information in “SubscriptionTypes”  
controller.

if credit card info is not valid then i redirect to again credit cards  
“new.html”.

When user select value “subscription type” from first form, I want to  
use that “subscription type” value in “SubscriptionTypes” controller.

I don’t know how to get that value? i used “session”.then I get value of  
“subscription type”, but if credit card info is not valid I get nil  
value when redirected to “new\_credit\_card.html.haml”?

Is there another way?

Thanks,  
Vikas.

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [June 8, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-view/169753/2 "2009-06-08T17:03:12Z")

</div>

On Mon, Jun 8, 2009 at 5:05 AM, Vikas  
Gholap[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> which is in controller “CreditCards”. This form is submitted to  
> “SubscriptionTypes” controller.
> 
> Then i validate credit card information in “SubscriptionTypes”  
> controller.
> 
> if credit card info is not valid then i redirect to again credit cards  
> “new.html”.

Redirecting will lose state.

I think instead of redirecting you want to render the new template,  
normally this is done within the same controller but if you really  
have to render a view from a different controller then

render :action =\> ‘new’, :controller =\> :credit\_cards

should do the trick, assuming you set up the controller instance  
variables which the view (and any partials) expects.

but really your description sounds a bit complex, I’d look at trying  
to get away from jumping between controllers.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [June 8, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-view/169753/3 "2009-06-08T22:51:05Z")

</div>

It seems like the two controllers could be combined. Validating the  
card and choosing a subscription type would be part of the same order,  
so you could add the subscription types to the credit card controller  
as an instance variable.

On Jun 8, 5:05 am, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
