Created
January 8, 2011 04:58
-
-
Save acconrad/770557 to your computer and use it in GitHub Desktop.
Page for reviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @review do |f| %> | |
<div class="field"> | |
<%= f.label :review_text, "Review:" %><br /> | |
<%= f.text_area :review_text %> | |
...rest of code ignore... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Review < ActiveRecord::Base | |
belongs_to :food | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReviewsController < ApplicationController | |
def index | |
food_item = Food.find(params[:company_id]) | |
@reviews = food_item.reviews | |
@review = Food.new | |
end | |
def create | |
food_item = Food.find(params[:food_id]) | |
@review = food_item.reviews.build(params[:review]) | |
if @review.save | |
flash[:success] = "Review created!" | |
redirect_to food_path(food_item) | |
else | |
render root_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment