Skip to content

Instantly share code, notes, and snippets.

@universal
Last active December 16, 2015 18:59
Show Gist options
  • Save universal/5481481 to your computer and use it in GitHub Desktop.
Save universal/5481481 to your computer and use it in GitHub Desktop.
<p>
<b>Comment:</b>
<%= comment.body %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.post, comment],
:confirm => 'Are you sure?',
:method => :delete %>
</p>
<%= form_for([@post, @post.comments.build]) do |f| %>
<div class="field">
<%= f.label :commenter %><br />
<%= f.text_field :commenter %>
</div>
<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
class Group < ActiveRecord::Base
attr_accessible :affiliation, :group_name, :group_type, :string
validates :group_name, :presence => true
has_many :posts, :dependent => :destroy
accepts_nested_attributes_for :posts
end
class Post < ActiveRecord::Base
attr_accessible :body, :posted_by, :posted_by_uid
validates :body, :presence => true
belongs_to :group
has_many :comments, :dependent => :destroy
end
# added "group_id" through migration
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :body, :commenter
end
Group Show
<p>
<b> Group Type </b>
<%= @group.group_type %>
</p>
<h1>New post</h1>
<%= render 'posts/form' %>
<p>
<b>Posts</b>
<%= render @group.posts %>
</p>
Posts partial
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Posts Show
<p id="notice"><%= notice %></p>
<p>
<b> Content </b>
<%= @post.body %>
</p>
<h2>Comments</h2>
<%= render @post.comments %>
<h2>Add a comment:</h2>
<%= render "comments/form" %>
<br />
Posts Form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment