Domanda

I'm new to rails and i'm sure this is a simple question but I haven't been able to find it. I have a product model and a sku model. A product has_many skus. I have a route setup to use a path like this: /products/1/skus/3

What I'm trying to figure out is how to link to different skus from this view using a link_to method. e.g.: = link_to @product_path + @sku_path and have it come out to be <a href="/products/1/skus/2">

@product and @sku are variables from the controller.

I know I could use a join and pass in the id's etc. But I wasn't sure if there was a better way of doing it. Maybe use a helper?

Thanks!

È stato utile?

Soluzione

Give that you have

#routes.rb
resources :products do
  resources :skus
end

you should be able to do

product_sku_path(@product, @sku)

to get a given sku associated with a product, good luck :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top