# How do you access params that are both model based and non model based?

**URL:** <https://www.ruby-forum.com/t/how-do-you-access-params-that-are-both-model-based-and-non-model-based/173257>\
**Category:** Rails\
**Created:** [August 5, 2009, 8:20pm UTC](https://www.ruby-forum.com/t/how-do-you-access-params-that-are-both-model-based-and-non-model-based/173257 "2009-08-05T20:20:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgeggatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jgeggatt](https://www.ruby-forum.com/u/jgeggatt)\
**Post date:** [August 5, 2009, 8:20pm UTC](https://www.ruby-forum.com/t/how-do-you-access-params-that-are-both-model-based-and-non-model-based/173257/1 "2009-08-05T20:20:54Z")

</div>

Hi all

Ive got a form thats based on a model that I need to put a drop down  
box and additional text field to build the description for the item.

heres some quick code

View

\<%= form\_for (@shape) do |f| %\>  
\<%= f.text\_field :description %\>  
\<%= select\_tag “shape\_name”, “roundsquare\</  
option\>triangular” %\>  
\<%= text\_field\_tag “shape\_code” =\>

Controller

@shape.new  
@shape.description = params[:description]  
@shape.shape = “#{params[:shape\_name]} #{params[:shape\_code]}”  
@shape.save

What happens is I get the shape.shape set right (to the name from the  
select box and the code from the text field) but description is always  
empty,

Heres whats in the params when I do a raise shape.to\_yaml to debug it.

{“shape\_name”=\>“triangular”,  
“shape\_code”=\>“shape code is here”,  
“order”=\>{“description”=\>“this is a description”}  
“shape\_code”=\>“342”,  
“shape\_number”=\>“111”,  
“finish1”=\>“Silver”,  
“commit”=\>“Create”,

Can someone point out how I should be accessing the params so I can  
set the description of the shape?

Many thanks

Jonathan G.

---

<div class="post-metadata">

**Author:** ![jgeggatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jgeggatt](https://www.ruby-forum.com/u/jgeggatt)\
**Post date:** [August 6, 2009, 5:25am UTC](https://www.ruby-forum.com/t/how-do-you-access-params-that-are-both-model-based-and-non-model-based/173257/2 "2009-08-06T05:25:50Z")

</div>

Jonathan G. wrote:

> Hi all
> 
> Ive got a form thats based on a model that I need to put a drop down  
> box and additional text field to build the description for the item.
> 
> heres some quick code
> 
> View
> 
> \<%= form\_for (@shape) do |f| %\>  
> \<%= f.text\_field :description %\>  
> \<%= select\_tag “shape\_name”, “roundsquare\</  
> option\>triangular” %\>  
> \<%= text\_field\_tag “shape\_code” =\>
> 
> Controller
> 
> @shape.new  
> @shape.description = params[:description]  
> @shape.shape = “#{params[:shape\_name]} #{params[:shape\_code]}”  
> @shape.save
> 
> What happens is I get the shape.shape set right (to the name from the  
> select box and the code from the text field) but description is always  
> empty,
> 
> Heres whats in the params when I do a raise shape.to\_yaml to debug it.
> 
> {“shape\_name”=\>“triangular”,  
> “shape\_code”=\>“shape code is here”,  
> “order”=\>{“description”=\>“this is a description”}  
> “shape\_code”=\>“342”,  
> “shape\_number”=\>“111”,  
> “finish1”=\>“Silver”,  
> “commit”=\>“Create”,
> 
> Can someone point out how I should be accessing the params so I can  
> set the description of the shape?

Because you’re using form\_for it prefixes the form element names with  
the model name. Which in your case must not be Shape, but Order, seeing  
that params[:order][:description] contains the description.

That is how you access the value by the way:  
params[:order][:description]

Honestly though, I’m really not sure why the description is going into  
params[:order], is Order really the model name? I’m going to assume  
so…

Here’s a brief, potentially correct explanation of how this all works.

\<input name=“order[description]” … /\>

This gets pulled into the params hash as params[:shape][:description].  
Following this naming convention for your form items (or using f.select  
and f.text\_field with form\_for) will give you the ability to use this  
syntax:

@order = Order.new(params[:order])  
@order.save

Best,  
Michael G.
