以下是相关代码:
--- 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
在控制台上,@comments返回
#<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 }
用户未登录时,呈现“ =部分”处的部分。
问题出在这里(我怀疑):
--- 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:,url: new_comm...
... ^
/app/views/shared/_new.html.erb:12: syntax error,unexpected keyword_ensure,expecting end-of-input
ensure
^~~~~
我希望这会有所帮助,再次感谢您的任何投入。