-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no senti que avanzo nada. problemas con comentarios polimorficos
- Loading branch information
Showing
5 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
class CommentsController < ApplicationController | ||
def index | ||
@question_answer = find_question_answer | ||
@comments = @question_answer.comments | ||
end | ||
|
||
def create | ||
@question_answer = find_question_answer | ||
@comment = @question_answer.comments.create(params[:comment]) | ||
redirect_to polymorphic_path[@question_answer, Comment] | ||
end | ||
|
||
private | ||
|
||
def find_question_answer | ||
params.each do |name, value| | ||
if name =~ /(.+)_id$/ | ||
return $1.classify.constantize.find(value) | ||
end | ||
end | ||
nil | ||
end | ||
|
||
end |
This file contains 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
This file contains 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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class Answer < ActiveRecord::Base | ||
belongs_to :question | ||
attr_accessible :content | ||
has_many :comments, :as => :question_answer, :dependent => :destroy | ||
has_many :comments, :as => :question_answer | ||
|
||
end |
This file contains 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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Question < ActiveRecord::Base | ||
attr_accessible :content, :title | ||
has_many :answers, :dependent => :destroy | ||
has_many :comments, :as => :question_answer, :dependent => :destroy | ||
has_many :answers | ||
has_many :comments, :as => :question_answer | ||
end |
This file contains 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