rails render an action with nested route -
i have nested resource so:
resources :contacts resource :leads end
when render edit view, url looks so:
http://localhost:3000/contacts/1/leads/1
when submit form , goes leads controller update action:
def update if @lead.update_attributes(lead_params) redirect_to contact_lead_path(@lead.contact, @lead) else render :edit end end
when else triggered, renders page so:
http://localhost:3000/leads/1
when should be:
http://localhost:3000/contacts/1/leads/1/edit
why doesn't "render :edit" account full nested url? how can resolve this?
look @ way form set in view. should following. leadscontroller#edit
method need load both @contact
, @lead
.
<%= form_for [@contact, @lead] |f| %> ... <% end %>
the fact you're getting non-nested-resource url form suggests you're not using pattern, , should.
also, assume typo, in question, you're declaring nested route as
resource :leads
instead of
resources :leads
the singular resource
valid, means different you're intending here, i.e., each contact
has 1 associated lead
.
Comments
Post a Comment