I am trying to route to a nested resource from a resource using friendly\_id. Below is the code:

routes.rb:

```
 resources :products do
   resources :reviews, except: [:index]
 end

```

rake routes:

```
new_product_review GET        /products/:product_id/reviews/new(.:format)

```

controller:

```
@review = Review.new(product_id: params[:product_id])

```

view button on the specific product page:

```
<%= link_to(raw("<button>Write a Review</button>"), new_product_review_path(@review.product_id, @review) ) %>

```

product URL:

```
http://localhost:3000/products/light-saber #just kidding

```

However, I am getting the error of:

```
undefined method `product_id'

```

What am I doing wrong here?

Update -----

Now in my controller I have:

```
before_filter :setup_product

@review = @product.reviews.new

def setup_product
    @product = Product.find(params[:product_id])
end

```

I am still getting the same error though. My question explicitly is, since my URL is not passing in an integer ID because I am using friendly\_id, is the param structured so that the controller can retrieve the product like I want?

UPDATE:

Now I am getting this error:

```
No route matches {:action=>"new", :controller=>"reviews", :product=>nil}

```

I get this when I change the code in my Product page to:

```
<%= link_to(raw("<button>Write a Review</button>"), new_product_review_path(@review) ) %>

```