我有一个名为 Listings 的资源和一个名为 email 的资源
列表 has_many :emails email belongs_to :listing
我正在尝试将列表 ID 传递给 email.listing_id 但我不断收到此错误:
Couldn't find Listing without an ID ActiveRecord::RecordNotFound in EmailsController#create
这是我的代码:
class EmailsController < InheritedResources::Base
def new
@listing = Listing.find(params[:listing_id])
@email = Email.new
end
def create
@listing = Listing.find(params[:listing_id])
@email = Email.new(params[:email])
@email.user_id = current_user.id
end
从我的列表显示页面我传递了listing.id
<%=link_to "Email Listing", new_email_path(:listing_id => @listing.id)
电子邮件_form
<%= f.input :email %>
<%= f.input :message %>
<%= f.hidden_field :listing_id, :value => @listing.id %>
%= f.button :submit, :value=> "Send Email" %>
参数:
"email"=>{"email"=>"xyz@z.com",
"message"=>"hello",
"listing_id"=>"3"},
"commit"=>"Send Email"}