문제

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!

도움이 되었습니까?

해결책

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 :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top