0

I have model Product with has_may :benefits, now in link_to for new benefit I don't know how to send ID of product so I can go with

Product.find(params[:id]).benefits.new(...)

Normal new method is

<%= link_to t('add_new_benefit'), new_admin_benefit_path %>

I want to send @product object so I can get id from it.

I wanna send it like this

<%= link_to t('add_new_benefit'), new_admin_benefit_path(@product) %>

routes.rb

...
namespace :admin do
      root "action_logs#index"
      get "toolkit", to: "toolkit#index"
      resources :admins
      resources :products
      ...
      resources :benefits
end
raideR49
  • 79
  • 6

1 Answers1

0

I believe you just want to pass id as a param. Eg:

<%= link_to t('add_new_benefit'), new_admin_benefit_path(product_id: @product.id) %>

Many examples here

Alexander
  • 1,072
  • 1
  • 5
  • 9