我是 Rails 的新手,我一直在努力弄清楚如何在我的“评论”页面(现在是索引页面)上呈现我的“日志”。
即使在我的审阅控制器中定义了日志,我仍然会收到 nomethoderror。
评论控制器
ReviewsController < ApplicationController
def index
@reviews = Review.all.order('created_at DESC').paginate(:page => params[:page], :per_page => 2)
end
def show
@logs = @logs.all
end
def new
@review = current_user.reviews.build
end
def edit
end
def create
@review = current_user.reviews.build(review_params)
if @review.save
redirect_to @review, notice: 'review was successfully created.'
else
render action: 'new'
end
end
def update
if @review.update(review_params)
redirect_to @review, notice: 'Review was successfully updated.'
else
render action: 'edit'
end
end
def destroy
@review.destroy
redirect_to reviews_url
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_review
@review = Review.find(params[:id])
end
def correct_user
@review = current_user.reviews.find_by(id: params[:id])
redirect_to reviews_path, notice: "Not authorized to edit this review!" if @review.nil?
end
# Never trust parameters from the scary internet, only allow the white list through.
def review_params
params.require(:review,).permit(:description, :attachment)
end
我的评论/index.html/erb
<div id='reviews' class='transitions-enabled'>
<% @reviews.each do |review| %>
<div class='box panel panel-default'>
<div class='panel-body'>
<p><%= review.description %></p>
<p><strong><%= review.user.name if review.user %></strong></p>
<%= link_to Time.now.strftime("%m/%d/%Y"), review %>
<% if review.user == current_user %>
<div class='actions'>
<%= link_to edit_review_path(review) do %>
<span class="glyphicon glyphicon-edit"></span> Edit
<% end %>
<%= link_to review, method: :delete, data: { confirm: 'Are you sure?' } do %>
<span class="glyphicon glyphicon-trash"></span>Delete
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
<%= render template:"logs/show" %>
<%= link_to new_review_path do %>
<span class="glyphicon glyphicon-pencil"></span>New Review
<% end %>