last day (14 days later) » 

5:13 PM
0
A: Select_Tag only selecting the first value

Kinaan Khan Sherwaniif you go through the documentation of options_for_select you will find that if you need to select a an option by default you will have to pass it as a 2nd parameter to options_for_select So in your case it would be something like this <%= select_tag 'address_id', options_for_select([user_addre...

 
It works for the subscription, but I get a ''undefined method `id' for nil:NilClass' error ont he @selected_address.id
 
@selected_address need to be the object , I guess in your case it should be object of UserAddress I am guessing this model on the base of convention.
 
Just checked again and for the 'plan' it now only passes the second option. How do I just pass what the user selected?
 
Passing or Selecting ?
 
Passing. I want the user to select and option and for that to pass into the form
 
5:13 PM
can you paste the whole partial/view in your question and that specific controller action where you want to pass the params ?
 
hey I just updated the code - think you know what is going on?
i'm just confused as to why using the select_tag is so complicated here
 
5:24 PM
can you place a debugger in create action and paste here what are the params ?
 
sorry what do you mean?
I'm a newbie
but its simple not passing the option selected. Why does this have to do with the controller
 
this will help us debug.
you can place a debugger like this

def create
debugger
 
got it
 
and when you submit the form, open the console
where your server is running
 
ok
 
5:30 PM
and run
`p params`
and paste the result here
 
so submit the form and run p params
do i type that in where i am running rails server
or do I open rails console and then do it
 
type where rails server is running
it should actually halt the server
and show debugger console
when you submit the form.
 
one second
i need to add the gem it said
 
yeah .. if you are using ruby 2.0+
add byebug gem
 
okay so it is running
Started POST "/charges" for 127.0.0.1 at 2015-08-29 13:35:20 -0400
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ODCtnWTrGCm4paUN+FdWAMkgDd9U5fEBy3+rC2Td+00=", "stripeToken"=>"tok_16fDEX25VdkYH2v6iIXpo2JA", "stripeEmail"=>"renaldo.webb@gmail.com", "amount"=>"1630", "tax"=>"133.125", "address_id"=>"13", "chickenVegetables_quantity"=>"3", "chickenRice_quantity"=>"0", "beefCouscous_quantity"=>"0", "beefVegetables_quantity"=>"0", "user_id"=>"10"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10 ORDER BY "users"."id" ASC L
i don't see plan anywhere there
 
5:39 PM
oh ..
you missed
options_for_select
 
what do you mean?
 
<%= select_tag 'plan',options_for_select(["One Time Order","Weekly Subscription"]) %>
try it and see if it solves the issue
just type c in the debugger and press enter
 
its still not showing plan in the debugger and it is pulling the wrong address
it is still just pulling the first entry
 
did you add the options_for_select ?
 
yes
 
5:48 PM
do you think some javascript is changing the value of select before submitting the form ?
 
that could be it
i have the javascript in a couple of places with the same form in different conditionals
 
can you paste that javascript
 
its just the var handler stuff you see in the original question
i have it pasted three times and something weird is happening with it
 

last day (14 days later) »