ruby on rails 3 - How to capture a comment's author then display in tooltip? -
I have a form attached to the profile, where concise comments can be submitted. I want to capture the name of the author, though I can display it in the tooltip when the comment is hovering over the body.
I have my inside my migration: profile model: comment models : / P> profile controller: and my form: I was thinking of using that support to add and display the author_id to current_user.profile.id: first_name and: last_name which are the properties of the profile. Update: I have got to show this name, though I am still curious if there is a better way. Your solution looks ok, but I in Then you can change your migration here: and for your controller method: Use tooltip in your view (I used the create method in my controller:
def make @ comment = comment.New (consultation []: ) @ commented out! Redirect_to profile_path (@ comment.profile) end
t.timestamps t.integer: profile_id t.string: author_id t String:
related_to: user accepts_nested_attributes_for: user has_many: comments
related_to: profile
def show @user = User.find ( Params [: id]) @profile = user.profile @superlative = @ profile.superlatives.new end
& lt; % = Form_for @comment do F | & Gt%; & Lt;% = f.hidden_field: profile_id ,: value = & gt; @ Profile id = & gt; & Lt;% = f.hidden_field: author_id ,: value = & gt; "# {Current_user.profile.first_name} # {current_user.profile.last_name}"%> & Lt;% = f.text_field: body% & gt; & Lt;% = f.submit 'Add New'% & gt; & Lt;% end% & gt;
user (or whatever class
current_user
profile :
app / model / comment .rb :
t.integer: author_id
def can create @comment = comment.New (params [: comment]. Major (: author_id = & gt; ; Current_user.id)) @ Comment.save! Redirect_to profile_path (@ comment.profile) end
title attribute, but use the method you like Do not hesitate to):
& lt; Div class = "comment" title = "& lt;% = @ comment.author.profile.first_name%> & lt;% = @ comment.author.profile.last_name% & gt;" & gt; & Lt;% = @ comment.body% & gt; & Lt; / Div & gt;
Comments
Post a Comment