Created
December 7, 2012 20:29
-
-
Save mstarkman/4236267 to your computer and use it in GitHub Desktop.
Nate Help
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
###### Original code | |
class RepliesController < ApplicationController | |
before_filter :signed_in_user, only: [:create, :edit] | |
#before_filter :correct_user, only: [:edit] | |
def new | |
@reply = conversation.replies.build | |
end | |
def create | |
@reply = conversation.replies.build(params[:reply], user_id: current_user.id) | |
if @reply.save | |
flash[:success] = "Post created!" | |
redirect_to root_url | |
else | |
redirect_to root_url | |
end | |
end | |
private | |
def signed_in_user | |
unless signed_in? | |
store_location | |
redirect_to signin_url, notice: "Please sign in." | |
end | |
end | |
def correct_user | |
@reply = current_user.replies.find_by_id(params[:id]) | |
redirect_to root_url if @conversation.nil? | |
end | |
end | |
####### Updated Code | |
class RepliesController < ApplicationController | |
before_filter :signed_in_user, only: [:create, :edit] | |
#before_filter :correct_user, only: [:edit] | |
def new | |
@reply = conversation.replies.build | |
end | |
def create | |
@reply = conversation.replies.build(params[:reply], user_id: current_user.id) | |
if @reply.save | |
flash[:success] = "Post created!" | |
redirect_to root_url | |
else | |
redirect_to root_url | |
end | |
end | |
private | |
def signed_in_user | |
unless signed_in? | |
store_location | |
redirect_to signin_url, notice: "Please sign in." | |
end | |
end | |
def correct_user | |
@reply = current_user.replies.find_by_id(params[:id]) | |
redirect_to root_url if @conversation.nil? | |
end | |
def conversation | |
@conversation ||= Conversation.find(params[:conversation_id]) | |
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
<!-- Original --> | |
<% provide(:title, @conversation.subject) %> | |
<%= render 'conversation_init' %> | |
<%= form_for(@reply) do |f| %> | |
<%= render 'shared/reply_form', f: f %> | |
<%= f.submit "Reply", class: "btn btn-large btn-primary" %> | |
<% end %> | |
<!-- Updated --> | |
<% provide(:title, @conversation.subject) %> | |
<%= render 'conversation_init' %> | |
<%= form_for([@conversation, @reply]) do |f| %> | |
<%= render 'shared/reply_form', f: f %> | |
<%= f.submit "Reply", class: "btn btn-large btn-primary" %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh I forgot to put this code back in before the reply form:
<% if @reply_items.any? %>
<%= render 'reply_item', collection: @reply_items %>
<% end %>