mardi 23 décembre 2014

How to save multiple checkbox values to string before create?

in view



<input id="checkbox-1" type="checkbox" value="drama" name="user[book][]">
<input id="checkbox-2" type="checkbox" value="poem" name="user[book][]">
<input id="checkbox-3" type="checkbox" value="fantasy" name="user[book][]">


if checked 1 and 3 checkbox, it is expected that something like "drama, fantasy" save in field book


in controller



private
def user_params
params[:user][:book] = params[:user][:book].join(',')
params.require(:user).permit(title, email, :book, message)
end


When I try to save the form input to database i get the following error:



Template is missing




Aucun commentaire:

Enregistrer un commentaire