Ruby on rails 嵌套注释,错误。轨道4。很抱歉,出了点问题
所以,我处于环境模式。我的错误是:很抱歉,出了点问题。 我的意见:Ruby on rails 嵌套注释,错误。轨道4。很抱歉,出了点问题,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,所以,我处于环境模式。我的错误是:很抱歉,出了点问题。 我的意见: def create @post = Post.find(params[:post_id]) @user = current_user @comment.user_id = @user.id @comment = @post.comments.create(params[:comment].permit(:body)) redirect_to @post end Show file posts/Show您应
def create
@post = Post.find(params[:post_id])
@user = current_user
@comment.user_id = @user.id
@comment = @post.comments.create(params[:comment].permit(:body))
redirect_to @post
end
Show file posts/Show您应该检查站点/服务器错误日志以获取特定的错误消息。最有可能的是一个你不期望的值是nil。你能在helper表格中使用这样的括号吗?我想它应该是括号。另外,我认为您可能正在寻找这个-devlog:Started GET/posts/18 for 127.0.0.1 at 20140326 Process PostsControllershow as HTML参数:{id=>18}[1m[35mUser Load 0.5ms[0m SELECT users.*FROM users WHERE.id=1 ORDER BY users.id ASC LIMIT 1[1m[36mPost Load 0.3ms[0m[1m SELECT posts.]FROM posts.id=?LIMIT 1[0m[[id,18][1m[35mUser加载0.3ms[0m选择用户。*来自用户,其中users.id=?限制1[[id,1]]Rendered comments/_form.html.erb 7ms Rendered posts/show.html.erb in layouts/application 12ms在29ms中完成500个内部服务器错误还尝试了:接受\u嵌套的\u属性\u for:posts controller中的注释。没有效果。请共享您的posts/show.html.erb文件
<%= form_for [@post, Comment.new] do |f| %>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
#comments:
belongs_to :user
belongs_to :post
#user:
has_many :posts
has_many :comments
#posts:
belongs_to :user
has_many :posts
resources :posts do
resources :comments
end
<h1><%= @post.title %><small> - Pagina postării</small></h1>
<div class="alert alert-info">
<b><%= link_to 'Înapoi', posts_path %></b>
<% if current_user == @user %>
|
<%= link_to 'Editează', edit_post_path %> |
<%= link_to 'Șterge', post_path, method: :delete, data: { confirm: 'Esti sigur?'}, class: "text-danger"%>
<% end %>
</div>
<p>
<strong>Autor:</strong>
<%= @user.email %>
</p>
<p>
<strong>Text:</strong>
<%= @post.body %>
</p>
<%= render "comments/form" %>