postgresql - Simple_form and Rails - multiple choice -
i'm trying make form simple_form , there multiple choice part. data saved (i have name, surname, email...), multiple choice radio button empty string. how make simple list of choices , save choice?
schema:
create_table "greetings" |t| t.string "first_name" t.string "last_name" t.string "nickname" t.string "multiple_choice" end
controller:
def new @greeting = greeting.new end def create @greeting = greeting.new(greeting_params) @greeting.save end private def greeting_params params.require(:greeting).permit(:first_name, :last_name, :nickname, :multiple_choice) end
logs:
started post "/greeting" ::1 @ 2017-07-28 17:32:19 +1000 processing greetingscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "greeting"=>{"first_name"=>"john", "last_name"=>"doe", "nickname"=>"johnny", "multiple_choice"=>""}, "multiple_choice"=>"name", "commit"=>"submit"} (0.2ms) beginsql (0.4ms) insert "greetings" ("first_name", "last_name", "nickname", "multiple_choice", "created_at", "updated_at") values ($1, $2, $3, $4, $5, $6, $7) returning "id" [["first_name", "john"], ["last_name", "doe"], ["nickname", "johnny"], ["multiple_choice", ""], ["created_at", 2017-07-28 07:32:19 utc], ["updated_at", 2017-07-28 07:32:19 utc]]
i want make multiple choice by:
- name
- surname
- nickname
i tried in view.slim
:
= simple_form_for @contact_form |f| = f.input :first_name, label: 'first name', placeholder: 'enter first name...' = f.input :last_name, label: 'last name', placeholder: 'enter last name...' = f.input :nickname, label: 'nickname', placeholder: 'enter nickname...' = f.input :multiple_choice, :collection => ['name'], :as => :radio_buttons = f.input :multiple_choice, :collection => ['surname'], :as => :radio_buttons = f.input :multiple_choice, :collection => ['nickname'], :as => :radio_buttons
but saves empty string.
thanks!
i found solution radio buttons:
view.slim: p name = f.radio_button :call_time, 'first_name' p surname = f.radio_button :call_time, 'last_name' p nickname = f.radio_button :call_time, 'nickname' = f.button :submit
Comments
Post a Comment