When a user is browsing through a listing of a model, I'd like him to be able to, say, click on a button/link that will open a form that will allow the user to add a comment on the current record. I have already installed the acts_as_commentable plugin, done the migration of the Comments table, added the acts_as_commentable directive to the class (say, the class name is Task). I have read the tutorial/instruction in the TechKnow Zenze web site, but it doesn't have enough details for me. I've got plenty of questions to ask to finish my project (I am a researcher and a newbie Ruby and RoR programmer).
fundedPeople succeed in answering rmc's questions 0% of the time (0 success in 2 attempts).
Answers by: Rich Collins | Federico
Hi,
you need also to create a new "comments" table:
1/ create a new migration: script/generate migration acts_as_commentable
2/ paste the code below into the migration file:
def self.up
create_table :comments, :force => true do |t|
t.column :title, :string, :limit => 50, :default => ""
t.column :comment, :string, :default => ""
t.column :created_at, :datetime, :null => false
t.column :commentable_id, :integer, :default => 0, :null => false
t.column :commentable_type, :string, :limit => 15,
:default => "", :null => false
t.column :user_id, :integer, :default => 0, :null => false
end
add_index :comments, ["user_id"], :name => "fk_comments_user"
end
def self.down
drop_table :comments
end
3/ run: rake migrate
4/ then you need to create a view for the comment form linked to your model
5/ in the comment controller you add a new comment to your model with:
comment = Comment.new(:title => titleStr, :comment => commentStr)
object.comments << comment
more details at:
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
Hi, Federico:
Thank you for your reply. Yes, I've done steps 1 - 4. What would be useful for me at this point:
a) code underlying a "Create Comment" link, which will be in a list or show view of a model, that will open the create view of the comment model.
b) code underlying the create comment view that will prompt for comment title and comment text, and then save the comments on submit.
Once again, thank you for reply, and best regards,
rmc