我正在尝试提交表单并收到此错误:Couldn't find Event without an ID
这是控制器:
def create
@event = Event.find(params[:event_id])
@event_sponsorship = EventSponsorship.new(params[:event_sponsorship])
@event_sponsorship.sponsor_id = current_user.id
@event_sponsorship.event_id = @event
respond_to do |format|
if @event_sponsorship.save
format.html { redirect_to @event_sponsorship, notice: 'Event sponsorship was successfully created.' }
format.json { render json: @event_sponsorship, status: :created, location: @event_sponsorship }
else
format.html { render action: "new" }
format.json { render json: @event_sponsorship.errors, status: :unprocessable_entity }
end
end
end
这是表格:
<%= simple_form_for(@event_sponsorship) do |f| %>
<%= f.error_notification %>
<div class="signin">
<%= f.hidden_field :event_id, value: @event %>
<%= f.hidden_field :sponsor_id, value: current_user.id %>
<%= f.button :submit, :class => "btn btn-success btn-block", value: "Yes" %>
</div>
<% end %>
在create
方法中event_id
应该从 URL 中找到。我哪里错了?