ruby - Unpermitted parameters for date_select rails not showing in database -
trying post date_select year, month , date database unable to. receiving next unpermitted parameters.
here binding.pry result
17: def create => 18: binding.pry 19: @timeslot = timeslot.new(timeslot_params) 20: 21: if @timeslot.save 22: flash[:notice] = "your timeslot created." 23: redirect_to timeslots_path(@timeslot) 24: else 25: render :new 26: end 27: end [1] pry(#<timeslotscontroller>)> params => {"utf8"=>"✓", "authenticity_token"=>"9qh4nsgc9ov2rj+cm/hruebc94oi63euwjzoqwl9qzm=", "timeslot"=>{"name"=>"5.30pm", "starts_at(1i)"=>"2014", "starts_at(2i)"=>"11", "starts_at(3i)"=>"13"}, "commit"=>"create timeslot", "action"=>"create", "controller"=>"timeslots"} [2] pry(#<timeslotscontroller>)> params.require(:timeslot).permit(:name, :"starts_at(1i).to_i", :"starts_at(2i).to_i", :"starts_at(3i).to_i") unpermitted parameters: starts_at(1i), starts_at(2i), starts_at(3i) => {"name"=>"5.30pm"} [3] pry(#<timeslotscontroller>)> params.require(:timeslot).permit(:name, starts_at: []) unpermitted parameters: starts_at(1i), starts_at(2i), starts_at(3i) => {"name"=>"5.30pm"} [4] pry(#<timeslotscontroller>)> params.require(:timeslot).permit(:name, starts_at: [(1i), (2i), (3i)]) unpermitted parameters: starts_at(1i), starts_at(2i), starts_at(3i) => {"name"=>"5.30pm"} [5] pry(#<timeslotscontroller>)>
this strong params whitelist controller
def timeslot_params params.require(:timeslot).permit(:name, :"starts_at(1i).to_i", :"starts_at(2i).to_i", :"starts_at(3i).to_i") end
this form
<div class='well'> <%= simple_form_for @timeslot |f| %> <div class='control-group'> <%= f.label :name %> <%= f.text_field :name %> </div> <div class='control-group'> <%= f.label :starts_at %> <%= f.date_select :starts_at %> </div> <%= f.submit(@timeslot.new_record? ? 'create timeslot' : 'update timeslot', class: 'btn btn-primary')%> <% end %> </div>
i using rails 4.1.6 / ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0].
the database schema type of "starts_at" in datetime format.
any help appreciated, in advance.
if have starts_at model attribute add together this:
params.require(:timeslot).permit(:name, :starts_at)
if not add together attr_accessible :starts_at
in model ,
params.require(:timeslot).permit(:name, :starts_at)
it work.
ruby-on-rails ruby
No comments:
Post a Comment