views:

53

answers:

2

Hi,

I use:

<%= select( "payment", "id", { "Visa" => "1", "Mastercard" => "2"}) %>

and I get this in HTML

<select id="payment_id" name="payment[id]"><option value="2">Mastercard</option>
<option value="1">Visa</option></select>

now how can I read the payment[id] with params[], if I use params[payment[id]] I get an error.

+1  A: 

I suppose is better to have

params[:payment][:id]

Params is a hash and can be contain some other hash.

shingara
shouldn't this be params[:payment][:id]
Mike Trpcic
yes to quick, I fix
shingara
+1  A: 

This one had me stumbled for a couple of hours when I first started with ruby/rails. In your controller and views you can access the payment's id with either:

params[:payment][:id]

or...

params['payment']['id']

Many people prefer using symbols (:symbol) over strings because of memory usage, no matter how small the gains...

Joseph Rodriguez