# Non model cascading selects

**URL:** <https://www.ruby-forum.com/t/non-model-cascading-selects/142398>\
**Category:** Rails\
**Created:** [July 7, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/non-model-cascading-selects/142398 "2008-07-07T15:36:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@thor](https://www.ruby-forum.com/u/thor)\
**Post date:** [July 7, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/non-model-cascading-selects/142398/1 "2008-07-07T15:36:50Z")

</div>

In my model I have a city\_id. ON the form I am using a cascading select  
to select the state, which then does a remote\_submit to get the list of  
cities (and hence the city\_id) for the selected state. The problem that  
I am having is that if I make a selection, hit SUBMIT and validation  
fails, the original selected state/city is now reset (ie, the values  
aren’t saved). Since they aren’t part of the model do I assign them to  
the flash or session? How do you set the initial values from these  
hashes?

Thanks

---

<div class="post-metadata">

**Author:** ![thor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@thor](https://www.ruby-forum.com/u/thor)\
**Post date:** [July 8, 2008, 1:14am UTC](https://www.ruby-forum.com/t/non-model-cascading-selects/142398/2 "2008-07-08T01:14:12Z")

</div>

initialize it in the controller and the re-assign it in your remote  
action in the controller, form the params

def create

# do your stuff

@selected\_city = params[:city]  
@selected\_city ||= City.first  
render :action =\> show  
end

then you can use @selected\_city when you come back to the view

\<%= select ( …, :selected =\> @selected\_city %\>

hope it helps

j
