开发者

Ruby on Rails 3 multiple tables

开发者 https://www.devze.com 2023-02-02 22:18 出处:网络
This is my first ROR application, so this is probably a basic question.I\'m building a review site where users submit reviews.

This is my first ROR application, so this is probably a basic question. I'm building a review site where users submit reviews.

I have a User model, a Review model, a Location model, and a Category model. The Category model belongs to the Location model, and I have that the Review model belongs to the User model. User has many reviews and Locations has many categories.

So when a user navigates the site they see a direc开发者_如何学Pythontory of locations (~/locations), clicks on a link to a location, which then displays the Categories for that locations (~/locations/:id/categories). When the user clicks on a category (~/locations/:id/categories/:id) I have a new review link on the page which sends the user to a form to create a new review (~/users/:id/reviews/new).

The problem I'm having is how do I send the category_id and location_id along with the user's review. I need the additional ids to show the reviews for the correct category, As of now, the user goes to ~/users/:id/reviews/new to create their review, which allows me to easily grab the user_id. How do I also get the category_id and location_id?

Any input is appreciated.


If the link is on a page where you have both the category and location, one option would be to pass them as query strings by creating your link with something like this:

<%= link_to "New Review", new_user_review_path(@user, :category_id => @category.id, :location_id => @location.id) %>

Then they are available in params

params[:category_id]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号