> On Mar 1, 2018, at 9:18 PM, Philip Rhoades <p...@pricom.com.au> wrote: > > Hassan, > > > On 2018-03-02 04:21, Hassan Schroeder wrote: >> On Thu, Mar 1, 2018 at 8:10 AM, Philip Rhoades <p...@pricom.com.au> wrote: >>> <%= b.label + b.radio_button %> >>> which actually works in the view but unlike the Checkbox version the data is >>> not saved in the tippers_tips table. >> The line above looks a bit iffy to me, but the main question is: what >> do you see in your logs? any error messages? >> If not use logging statements (or pry) to inspect the params being >> returned. > > > Thanks for responding - I see in the log when I edit a Tipper: > > Processing by TippersController#update as HTML > Parameters: {"utf8"=>"✓", > "authenticity_token"=>"AhTjh08BAh6NALIeQ5yc7qVvjO8S6rnBaCQlsocM6ffiVkKMo2eKaAmP/QBA2Iiu79naCW+Pd8XZsTMbnYbutQ==", > "tipper"=>{"fname"=>"Jocelyn", "tip_ids"=>"1"}, "commit"=>"Update Tipper", > "id"=>"3"} > Tipper Load (0.1ms) SELECT "tippers".* FROM "tippers" WHERE "tippers"."id" > = ? LIMIT ? [["id", 3], ["LIMIT", 1]] > Unpermitted parameter: tip_ids > > During the tables generation I did: > > rails g migration CreateJoinTableTipTipper tip tipper > > and the only two mentions of "tip_ids" is in app/views/tippers/_form.html.erb > : > > <div class="field"> > <%= f.label "Tip" %><br /> > <%= f.collection_radio_buttons( :tip_ids, Tip.all, :id, :teams ) do |b| %> > <div class="collection-radio-button"> > <%= b.radio_button %> > <%= b.label %> > </div> > <% end %> > </div> > > and app/controllers/tippers_controller.rb : > > params.require(:tipper).permit(:fname, tip_ids:[]) > > I deleted "[]" since there should be only one tip id returned but that caused > and error . . > > Thanks, > > Phil. > -- > Philip Rhodes
Rename the tip_ids to tip_id. A radio button only returns one value, and tip_ids means you are expecting an array back, as you would get from a group of checkboxes. Check your strong parameters (permit) clause in your controller -- make sure that it is set to accept a single scalar value for that form input (singular). Also check that the relationship in your models is not one to many, but one to one (has_one/belongs_to). Changing the type of input you want to use has ramifications for your entire application, not just the view. Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CCDA87D8-A80C-4A12-BA7B-415BD2A04FB5%40wdstudio.com. For more options, visit https://groups.google.com/d/optout.