How to nest a route

Asked

Viewed 23 times

2

Good afternoon,

I have a service order and need to generate a report through it, this report needs to receive the service order number to save in the order_id column. I’m trying to make a nested route:

My route is this way:

resources :orders do
    resources :vegoor_reports, only: [:create]
end

On the show page of my work order I have the way:

<%= link_to 'Laudo', order_vegoor_reports_path(@order), class: 'btn btn-primary' %>

I have the following routes to Orders:

order_vegoor_reports POST /Orders/:order_id/vegoor_reports(.:format) vegoor_reports#create

When I go to the Report button the following error occurs:

No route Matches [GET] "/Orders/1/vegoor_reports"

Can anyone point me in the wrong direction? Thank you

  • Olá Eduardo, esse link_to é para criar um laudo ou para para o formulário de criação de um laudo?

  • This link to is to create the form that creates the report.

  • 1

    I left an answer if you did not understand or that was not what I needed tells me that I make the change.

1 answer

1


As you mentioned in the comment, this link is to go to the Report creation page, so the route/method 'new' is missing. For this reason returns the error, because you are trying to make a GET for a route that does not exist, what exists is only the POST for the 'create' method'.

I could do something like this:

resources :vegoor_reports, only: [:new, :create]

And on the controller:

def new
  @vegoor_report = VegoorReport.new
  # do something
end

So, you would first make a GET that renders the form view(new.html.erb) of Vegoorreport and then fill in the form makes the POST for the 'create.erb) method'.

It seemed?

  • Good morning Henrique, Thanks for your return, I made the modification and it worked and I am able to access the form to create a new report. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.