1. Conclusion </ b>
2. How did you code it? </ B>
3. Development environment </ b>
Supplement </ b>
Code redirect_to "/XXXX/#{@@@@@.XXXX.id}" </ b>!
def create
@comment = Comment.new(comment_params)
if @comment.valid?
@comment.save
redirect_to "/reports/#{@comment.report.id}"
end
It is an application that allows you to add comments to a post called report. At that time, you can return to the first screen as root after adding comments to the report post. However, I wanted to return to the screen for posting comments, including checking if there are any comments left, so I coded like this.
Mac catalina 10.15.4
Vscode
Ruby 2.6.5
Rails 6.0.3.3
redirect_to report_path(id: current_user)
#Use devise gem.
However, no error will occur, but since it is current_user, if you register it first, it will be / reports / 1, and it will be returned to the first report, which is different from the report posted second, so be careful. Is required.
Recommended Posts