Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created August 16, 2012 03:21
Show Gist options
  • Save telagraphic/3366227 to your computer and use it in GitHub Desktop.
Save telagraphic/3366227 to your computer and use it in GitHub Desktop.
Nested Resources
<section class="comments">
<h2>Post A Comment</h2>
<%= form_for([@post, @comment]) do |comment| %>
<%= comment.label :email %><br/>
<%= comment.text_field :email %><br/>
<%= comment.label :body %><br/>
<%= comment.text_area :body, :size => "60x12" %><br/>
<%= comment.submit "Shout out" %>
<% end %>
</section>
class CommentsController < ApplicationController
before_filter :get_post
def get_post
@post = Post.find(params[:post_id])
end
def new
@comment = @post.comments.build
end
end
<%= link_to "Back", posts_path %>
<article class="post">
<h2><%= @post.title %><h2>
<h3><%= @post.created_at %></h3>
<section class="">
<iframe width="560" height="315" src="<%= @post.youtube %>" frameborder="0" allowfullscreen></iframe>
</section>
<p class=""><%= @post.content %></p>
<hr>
<% if user_signed_in? %>
<%= link_to "Edit", edit_post_path(@post) %>
<%= link_to "Destroy", @post, :confirm => "Are you sure", :method => :delete %>
<% end %>
<%= link_to "Back", posts_path %>
<%= render "comments/comment_form" %>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment