Created
August 31, 2012 02:09
This file contains hidden or 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 Comment < ActiveRecord::Base | |
attr_accessible :invitation_id, :comment | |
belongs_to :invitation | |
end |
This file contains hidden or 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 CommentsController < ApplicationController | |
# GET /comments | |
# GET /comments.json | |
def index | |
@comments = Comment.all | |
respond_to do |format| | |
format.html # index.html.test.erb | |
format.json { render :json => @comments } | |
end | |
end | |
# GET /comments/1 | |
# GET /comments/1.json | |
def show | |
@comment = Comment.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render :json => @comment } | |
end | |
end | |
# GET /comments/new | |
# GET /comments/new.json | |
def new | |
@comment = Comment.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render :json => @comment } | |
end | |
end | |
# GET /comments/1/edit | |
def edit | |
@comment = Comment.find(params[:id]) | |
end | |
# POST /comments | |
# POST /comments.json | |
def create | |
@comment = Comment.new(params[:comment]) | |
respond_to do |format| | |
if @comment.save | |
format.html { redirect_to @comment, :notice => 'Comment was successfully created.' } | |
format.json { render :json => @comment, :status => :created, :location => @comment } | |
else | |
format.html { render :action => "new" } | |
format.json { render :json => @comment.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /comments/1 | |
# PUT /comments/1.json | |
def update | |
@comment = Comment.find(params[:id]) | |
respond_to do |format| | |
if @comment.update_attributes(params[:comment]) | |
format.html { redirect_to @comment, :notice => 'Comment was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render :action => "edit" } | |
format.json { render :json => @comment.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /comments/1 | |
# DELETE /comments/1.json | |
def destroy | |
@comment = Comment.find(params[:id]) | |
@comment.destroy | |
respond_to do |format| | |
format.html { redirect_to comments_url } | |
format.json { head :no_content } | |
end | |
end | |
end |
This file contains hidden or 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 Invitation < ActiveRecord::Base | |
has_many :comments, :dependent => :destroy | |
accepts_nested_attributes_for :comments, :allow_destroy => true | |
end |
This file contains hidden or 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 InvitationsController < ApplicationController | |
respond_to :html, :json | |
# GET /invitations/1 | |
# GET /invitations/1.json | |
def show | |
@invitation = Invitation.find(params[:id]) | |
@comment = Comment.new | |
respond_with(@invitation) | |
end | |
end |
This file contains hidden or 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
# Other routes | |
resources :comments | |
resources :invitations do | |
member do | |
post :comments | |
end | |
end |
This file contains hidden or 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
<p> | |
<b>Title:</b> | |
<%= @invitation.title %> | |
</p> | |
<%= form_for [@invitation, @comment] do |f| %> | |
<%= f.text_area :comment, :rows => 3 %> | |
<%= f.submit "Submit" %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment