Problems with routing
I have an application that has one purchase_order for each purchase_request.
My models are set up like so
purchase_order.rb
...
belongs_to :purchase_request
...
purchase_request.rb
...
has_one :purchase_order
...
My routes are set up like so:
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. 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:
...
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:
<%= f.hidden_field :purchase_request_id, :value=>purchase_request_id %>
精彩评论