Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Forked from binnyg/gist:3542535
Created August 30, 2012 22:15
Show Gist options
  • Save tyler-smith/3542790 to your computer and use it in GitHub Desktop.
Save tyler-smith/3542790 to your computer and use it in GitHub Desktop.
Models
----------------------------------------
Invitation
has_many :comments
Comment
belongs_to :invitation
Controller
----------------------------------------
class InvitationsController < ApplicationController
def show
@invitation = Invitation.find(params[:id])
respond_with(@invitation)
end
end
routes.rb
----------------------------------------
resources :invitations do
member do
post 'create_comment'
end
end
View show.html.erb [http://localhost:3000/invitations/1]
----------------------------------------
<p>
<b>Title:</b>
<%= @invitation.title %>
</p>
<%= simple_form_for @comment, :url => create_comment_invitation_path(@invitation) do |f| %>
<%= f.input :comment, :label => 'Comment', :placeholder => 'Enter Comment' %>
<%= link_to 'Submit', create_comment_invitation_path(@invitation) , :class => 'btn' %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment