【发布时间】:2019-11-20 04:58:15
【问题描述】:
以下是相关代码:
--- app/controllers/movies_controller.rb
def show
movie = convert_movie_data([Movie.find(params[:id])])
@movie = movie[0]
@movie_rating = movie[1]
@comments = Comment.all
if user_signed_in?
@new_comment = new_movie_comment
end
end
在控制台,@cmets 返回
#<Comment id: nil, title: nil, comment: nil, user_id: 21, movie_id: 10, created_at: nil, updated_at: nil>
--- app/views/movies/show.html.haml
= render partial: 'shared/new', locales: { new_comment_form: @new_comment }
“= partial”处的部分在用户未登录时呈现。
这就是问题所在(我怀疑):
--- app/views/shared/_new.html.erb
<% if user_signed_in? %>
<%= simple_form for new_comment_form:, method: :post, url: new_comment_path do |f| %>
<%= f.input :title %>
<%= f.input :comment %>
<%= f.button :submit %>
<% end %>
You are signed in
<% else %>
Please sign in to comment
<% end %>
我怀疑问题出在我为标签构建 simple_form 的方式上。
在控制器上,我注入了构建评论所需的值(current_user.id,movie_id),在显示视图中,我尝试通过语言环境(new_comment_form:)传输实例变量,但我确信我在构造简单表单时犯了一个错误。
我被告知我没有提供错误消息。感谢您指出@z3r0ss
SyntaxError at /movies/21
syntax error, unexpected ','
...ple_form_for new_comment_form:, method: :post, url: new_comm...
... ^
/app/views/shared/_new.html.erb:12: syntax error, unexpected keyword_ensure, expecting end-of-input
ensure
^~~~~
我希望这会有所帮助,并再次感谢您的任何意见。
【问题讨论】: