Assume that you have a model named 'topic' in the form of a parent, and ' Comment'. On the URL 'Subject / Show / 35' you can see all comments related to this topic ID # 35.
When the logged-in user wants to post a new comment on this page, should I write 'Comment_create' in action_controller.rb? Or just write the 'create' function in comments_controller.rb, and call it from this page? Which method is regular ??
If I call the 'create' action in comments_controller, then how can I write to pass
- To add comments' model name '
- ' Model ID # '
- ' Comment body '
Or should I write a different way in this way?
Controllers / comments_controller.rb
def create_in_topic code here! The new comment is related to the topic which is related to the reference ... .def creation_in_user code here!
For your information, commenting should add something like this.
def make @topic = Topic.find (params [: topics] [: id]) @user_who_commented = current_user @comment = comment .build_from (@topic, @ user_who_commented.id, params [ : Topics] [: body]) @ comment.save Redirect_to: back flash [: notice] = "comment added!"
example & lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; Id & lt; / Th & gt; & Lt; Th & gt; Title & lt; / Th & gt; & Lt; Th & gt; Body & lt; / Th & gt; & Lt; Th & gt; Subject & lt; / Th & gt; & Lt; Th & gt; Posted by & lt; / Th & gt; & Lt; Th & gt; Remove & lt; / Th & gt; & Lt; / TR & gt; & Lt;% @ topic.comment_threads.each | Comment | & Gt%; & Lt; TR & gt; & Lt; Td> & Lt;% = comment.id% & gt; & Lt; / Td> & Lt; Td> & Lt;% = comment.title% & gt; & Lt; / Td> & Lt; Td> & Lt;% = comment.body% & gt; & Lt; / Td> & Lt; Td> & Lt;% = comment.subject% & gt; & Lt; / Td> & Lt; Td> & Lt;% = comment.user.user_profile.nickname If Comment.User.user_profile% & gt; & Lt; / Td> & Lt; TD & gt; ** Comment Destination Method Needed Here !!! ** & lt; / Td> & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Table & gt; & Lt;% = form_for: topics, url: url_ ((Controller =>: Subject: verb = & gt ;: add_comment) do; f | & gt;; & lt; div class = "field" & gt; ; <% = F.label: 'Comment'% & gt; & lt; br / & gt; & lt;% = f.text_field: body% & gt; & lt; / div & gt; & lt; % = F.hidden_field: id ,: value = & gt; @ Topic.id% & gt; & lt; div class = "verb" & gt; & gt;% = f.submit%> & gt; & lt;% End%>
controllers / topics_controllerRbb
def add_comment @topic = Topic.find (params [: topics] [: id]) @user_who_commented = current_user @ comment = comment .build_from (@topic, @ user_who_commented.id, params [: topics] [: body]) @ comment.save redirect_to: back flash [: notice] = "comment added!" I think the most direct forward execution is this one verb (ie: Add_comment). Once you call the TopicController # add_comment operation in your Subject Controller, you will also receive all your information and commentary data so that you can easily add comments on that topic.
Tell me if you need further help by fadex
Comments
Post a Comment