Skip to content

Instantly share code, notes, and snippets.

@acconrad
Created January 8, 2011 04:58
Show Gist options
  • Save acconrad/770557 to your computer and use it in GitHub Desktop.
Save acconrad/770557 to your computer and use it in GitHub Desktop.
Page for reviews
<%= form_for @review do |f| %>
<div class="field">
<%= f.label :review_text, "Review:" %><br />
<%= f.text_area :review_text %>
...rest of code ignore...
class Review < ActiveRecord::Base
belongs_to :food
end
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