Ruby on rails Rails 4控制器/模型关联和白名单属性
我有一个具有以下行的客户机模型:Ruby on rails Rails 4控制器/模型关联和白名单属性,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有一个具有以下行的客户机模型: has_many :payments 以及具有以下功能的支付模式: belongs_to :client 及 在我看来 <%= @payment.generate_sepa %> 不幸的是,我得到了以下错误: 未知密钥:id 为了 在客户端控制器中,我还有: def client_params params.require(:client).permit(:id, :trading_name, :company_name, :own
has_many :payments
以及具有以下功能的支付模式:
belongs_to :client
及
在我看来
<%= @payment.generate_sepa %>
不幸的是,我得到了以下错误:
未知密钥:id
为了
在客户端控制器中,我还有:
def client_params
params.require(:client).permit(:id, :trading_name, :company_name, :owner, :main_contact_name,
:email, :phone, :date_joined, :trading_street_one, :trading_street_two, :trading_town, :trading_county, :iban, :bic)
end
在付款方面:
def payment_params
params.require(:payment).permit(:client_id, :signup_fee, :monthly_fee, :date_of_payment, :payment_reference,
:remittance_information, :mandate_id, :mandate_date_of_signature, :batch_booking, :sequence_type, :is_recurring, :is_onceoff)
end
我把身份证列入白名单的方式有问题吗?或者客户和付款之间的联系有什么问题吗?因为,老实说,我很难弄清楚到底出了什么问题
编辑
:client_id在我创建新客户时会像这样传递到付款:
def create
@client = Client.new(client_params)
respond_to do |format|
if @client.save
format.html { redirect_to new_payment_url(:client_id => @client.id) }
format.json { render action: 'show', status: :created, location: @client }
else
format.html { render action: 'new' }
format.json { render json: @client.errors, status: :unprocessable_entity }
end
end
end
在部分付款表中,我还有:
<%= f.hidden_field('client_id', :value => params[:client_id]) %>
params[:client_id])%>
以及其他表单字段
def show
@client = Client.find(params[:client_id])
end
不是吗 在支付控制器/show
@client=client.find(params[:id])
中将不起作用
使用
因为您正在向展会传递付款id,而不是客户id。感谢您的建议,语法看起来更好,但我得到的是“找不到没有id的客户”。日志有相同的消息。你能发布你的相关视图模板吗?你能试试
Client.find(params[:id])
tkymtk它就在上面。在我看来,我真正拥有的是'edit'和'back'的链接@Thaha,它将支付id传递给客户,而不是正确的客户id,因此它不起作用。您如何传递客户id?。像这样<代码>客户端路径(@payment.id,客户端id:@client.id)。或者你可以分享这个网址吗?
def create
@client = Client.new(client_params)
respond_to do |format|
if @client.save
format.html { redirect_to new_payment_url(:client_id => @client.id) }
format.json { render action: 'show', status: :created, location: @client }
else
format.html { render action: 'new' }
format.json { render json: @client.errors, status: :unprocessable_entity }
end
end
end
<%= f.hidden_field('client_id', :value => params[:client_id]) %>
def show
@client = Client.find(params[:client_id])
end
@payment= Payment.find(params[:id])
@client = @payment.client