添加注释到posts = undefined局部变量或方法`post'for

时间:2016-03-28 22:01:34

标签: ruby-on-rails ruby-on-rails-3 methods

您好我有<form action="upload.php" method="post" enctype="multipart/form-data"> Your Photo: <input type="file" name="image" /> <input type="submit" name="submit" value="Submit" /> </form> <?php print_r($_FILES); // file properties $file_name = $_FILES['image']['name']; $file_tmp_name = $_FILES['image']['tmp_name']; $file_size = $_FILES['image']['size']; $file_error = $_FILES['image']['error']; // get the extension of the file $file_ext = explode('.', $file_name); $file_ext = strtolower(end($file_ext)); var_dump(file_exists('uploads')); // this is false if(chmod('uploads', 0777) ){ echo " booooh"; } else{ echo "naaah"; } $file_name_new = uniqid('', true) . '.' . $file_ext; echo "<br>"; echo $file_destination = '/uploads/' . $file_name; // this is false too if(move_uploaded_file($file_temp, $file_destination)) { echo "<br>$file_destination<br>"; echo "hello world<br>"; } else { echo "<br>file not uploaded<br>"; } ?>

这样的错误

我不明白,因为我在帖子中创建了一个名为undefined local variable or method 'post' for #<#<Class:0x007ffc40469ad0>:0x007ffc40461088>

的部分内容
_comments.html.erb

它呈现<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 %>

未定义的方法在此行<% render 'comments' %>

模型帖子是<%= simple_form_for [post, post.comments.new] do |f| %>

模型帖子是has_many :comments, dependent: :destroy

模型评论为has_many :comments, dependent: :destroy

路线是       资源:帖子做         资源:类别           资源:评论       端

评论控制器

belongs_to :user
                    belongs_to :post

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:1)

尝试更新以下内容:

<%= simple_form_for [post, post.comments.new] do |f| %>

用这个:

<%= simple_form_for [@post, @post.comments.new] do |f| %>