값을 내 컨트롤러에 제출했습니다. 서버 로그에서 매개 변수 (: 스타일)가 전달되지만 데이터베이스에 삽입되지는 않습니다. 누군가 일어날 수있는 방법을 알고 있습니까?매개 변수가 form_for에서 전달되었지만 데이터베이스에 삽입/커밋되지 않았습니다.
서버 로그
Started POST "https://stackoverflow.com/users/25/cupboards" for ::1 at 2016-08-19 19:11:39 -0400
Processing by CupboardsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"asWeoSFSisr62oMOPXZnb//KJ8LnAhT1h07NOm1Yn2O8t06N4yrDGugkd01AMQcujYzSahH+O7bEA/jpH+L9fQ==", "style"=>"WEEKEND", "commit"=>"Make a new closet", "user_id"=>"25"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 25]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 25]]
(0.1ms) begin transaction
SQL (0.5ms) INSERT INTO "cupboards" ("user_id", "created_at", "updated_at") VALUES (?, ?, ?) [["user_id", 25], ["created_at", "2016-08-19 23:11:39.219003"], ["updated_at", "2016-08-19 23:11:39.219003"]]
(0.7ms) commit transaction
Redirected to http://localhost:3000/users/25/cupboards/35/edit
Completed 302 Found in 46ms (ActiveRecord: 1.4ms)
형태
<%= form_for @cupboard, url: { action: "create" }, html: { class: "listform"} do |f| %>
<%= f.label "ATHLEISURE", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "ATHLEISURE") %>
<%= f.label "CASUAL", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "CASUAL") %>
<%= f.label "PROFESISONAL", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "PROFESSIONAL") %>
<%= f.label "WEEKEND", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "WEEKEND") %>
<%= f.label "FESTIVAL", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "FESTIVAL") %>
<%= f.label "DATENIGHT", class: "welcomelistitem" %>
<%= radio_button_tag(:style, "DATENIGHT") %>
<%= f.submit 'Make a new closet' %>
<% end %>
컨트롤러
def create
@user = User.find(params[:user_id])
@cupboard = @user.cupboards.new(cupboard_params)
if @cupboard.save
redirect_to edit_user_cupboard_path(@user, @cupboard)
else
render :new
end
end
에 Params
private
def cupboard_params
# I used .fetch because .permit wasnt working. workaround found at http://stackoverflow.com/questions/24944871/actioncontrollerparametermissing-param-is-missing-or-the-value-is-empty-film
params.fetch(:cupboard, {}).permit(:style, :season, :neutral1, :neutral2, :accent1, :accent2)
end
end
도움을 주셔서 감사합니다!
감사합니다. 도움이되었습니다. 태그를 제거한 것은 내 radio_button_tag였습니다. 그리고 f. 도움에 감사드립니다! – IWI
@Samy 굉장! 천만에요. – dskecse