ich eine teilweise in # Ansicht Post zeigen die Namen _comments.html.erbIn Schienen Ich kann den neuen Kommentar mit Iteration jeder Anzeige erstellt haben
hier es
<p class="text-center">Poster un commentaire</p>
<%= simple_form_for [post, post.comments.new] do |f| %>
<%= f.error_notification %>
<%= f.input :content, label: "Commentaire"%>
<%= f.submit "Envoyer", class: "btn btn-primary" %>
<% end %>
ist und es machen wie die <%= render 'comments' %>
und über die teilweise (in # Beitrag anzeigen Show) ich habe eine Iteration wie die
<ul class="list-unstyled">
<% @post.comments.each do |comment| %>
<li>
<p><% comment.content %></p>
<% end %>
</li>
</ul>
Aber nichts erscheint, wenn ich eine neue Nachricht erstelle, warum nicht.
Ich gebe Ihre mehr Code Details
post.rb
has_many :comments, dependent: :destroy
comment.rb
belongs_to :user
belongs_to :post
Die Route ist:
resources :posts do
resources :categories
resources :comments
end
Kommentare Controller ist
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)
@comment.user_id = current_user.id
if @comment.save
flash[:success] = "You commented the hell out of that post!"
redirect_to :back
else
flash[:alert] = "There is a problem with your comment"
render root_path
end
end
def destroy
@comment = @post.comments.find(params[:id])
@comment.destroy
flash[:success] = "Comment deleted :("
redirect_to root_path
end
private
def set_post
@post = Post.find(params[:post_id])
end
def comment_params
params.require(:comment).permit(:content, :post_id, :user_id)
end
end
Dank für Ihre Hilfe danken.
Wird beim Aktualisieren der Seite der neue Inhalt angezeigt? –
**
<% = comment.content%>
** - Versuchen ** <%= %> ** statt ** ** <% %> – dp7@ArslanAli die '=' fehlt –