[英]Problems with routing
I have an application that has one purchase_order for each purchase_request. 我有一个应用程序,每个purchase_request都有一个purchase_order。
My models are set up like so 我的模型设置如下
purchase_order.rb Purchase_order.rb
...
belongs_to :purchase_request
...
purchase_request.rb Purchase_request.rb
...
has_one :purchase_order
...
My routes are set up like so: 我的路线设置如下:
routes.rb routes.rb
resources :purchase_requests do
:purchase_orders
end
and in my view I link to it like so: 在我看来,我可以这样链接到它:
<%= link_to "Purchase Order", new_purchase_request_purchase_order_path(@purchase_request) %>
and in my form I have: 在我的表格中,我有:
<%= f.hidden_field :purchase_request %>
but it is not loading the id of the purchase_request. 但它不会加载Purchase_request的ID。 Any help would be great
任何帮助都会很棒
I am not sure if this is the proper way to do it but what I did: 我不确定这是否是正确的方法,但我不确定:
in the purchase_orders_controller I placed: 在我放置的purchase_orders_controller中 :
...
def new
@purchase_request = PurchaseRequest.find(params[:purchase_request_id])
...
then in the new view i did: 然后在新视图中,我做了:
<%= render 'form', :purchase_request_id=>@purchase_request.id %>
and last but not least, I put this in my _form partial: 最后但并非最不重要的一点,我将其放在我的_form部分中:
<%= f.hidden_field :purchase_request_id, :value=>purchase_request_id %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.