Home>
1
On the details page for the posted photo
I'm trying to implement a comment feature
First, I want to check "Save comment post"
On the details page (show.html.erb)
I posted it in the comment posting form
Just refresh the details page
Not stored in the database
Comments are not saved in the table
No error code is displayed
3 Applicable source code
show.html.erb
<main> <p> <% = "Prototype title"%> </p> <% = link_to "by # {@ prototype.user.name}", root_path, class:: prototype__user%> <% if user_signed_in?&¤t_user.id == @ prototype.user_id%> <% = link_to "edit", edit_prototype_path (@ prototype.id), method:: get, class:: prototype__btn%> <% = link_to "Delete", prototype_path (@ prototype.id), method:: delete, class:: prototype__btn%> <% end%> <% = image_tag @ prototype.image%> <p>Catch copy</p> <p> <% [email protected]_copy%> </p> <p>Concept</p> <p> <% = @ prototype.concept%> </p> <% if user_signed_in?%> <% = form_with (model: [@comment, @prototype],
local: true)
do | f |%>← ** This is the comment form part **
<% = f.label: text, "comment"%><br /><% = f.text_field: text%> <% = f.submit "submit", class :: form__btn%> <% end%> <% end%> <ul> <% # Describe the process of listing the comments associated with the post%> <li> <% #<% = "Comment text"%> <% #<% = link_to "(username)", root_path, class:: comment_user%> </li> <% # // Describe the process to list the comments associated with the post%> </ul> </main>
prototypes_controller.rb
class PrototypesController</pre>
<p><br />
comments_controller.rb</p>
<pre><code>class CommentsController</pre>
<p><br />
routes.rb</p>
<pre><code>Rails.application.routes.draw do
devise_for: users
root to:'prototypes # index'
resources: prototypes do
resources: comments, only :: create
end
end
4 What I researched and tried
Check the association
user model
has_many: prototypes
has_many: comments
prototype model
belongs_to: user
has_many: comments, dependent:: destroy
comment model
belongs_to: prototype
belongs_to: user
I was able to confirm the description of
Also once in the create action part
I used binding.pry,
The process did not stop
def create
binding.pry
@comment = Comment.new (comment_params)
if @ comment.save
redirect_to prototype_path (@ comment.prototype)
else else
@prototype = @ comment.prototype
@comments = @ prototype.comments
render "prototypes/show"
end
end
5 Supplementary information such as the version of the tool i am using
-
Answer # 1
Related articles
- how to view comments for posts in ruby on rails
- ruby - unable to open rails server
- ruby on rails - unable to create controller
- ruby on rails - i can't enter comments in topic when creating a simple bulletin board
- ruby - unable to create rails model (environment: cloud9)
- ruby on rails - unable to start server in aws production environment
- ruby on rails - unable to install direnv
- ruby - unable to access server with rails s
- ruby - [rails] unable to resolve "name error in affiliates controller # show" error
- ruby on rails - unable to access localhost with rails6 and docker
- ruby on rails - about saving comments
- ruby on rails - unable to get latitude/longitude from user registration
- ruby - rails unable to resolve user errors
- ruby on rails - [rails] i'm implementing a search function using form_with, but i'm having trouble with the search results not b
- ruby - about implementation of tag function in rails
- ruby on rails - i want to resolve rails nameerror
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby on rails - i would like to add an automatic address input function to the new registration screen
Related questions
- ruby - i want to get records that match multiple foreign keys from within an intermediate table
- ruby - about how to save db with rails devise
- ruby - when i try to save data from rails console, id, created_at, updated_at become nil
- how to write in ruby multiple loop controller
- ruby - output the total integer value held by each user
- ruby - i want to use two rails renders
- ruby - i can't get a payjp token on aws
- html - i want it to be rendered if the search word is incorrect
- ruby - about viewport introduction
- ruby - [rails] about the error that occurs when deleting likes (routing error)
form_with (model: [@comment, @prototype]
Description ofform_with (model: [@prototype, @comment]
How about trying it?If it doesn't go away, I'm sorry.