问题form_for:RAILS

时间:2018-03-03 22:28:22

标签: ruby-on-rails ruby ruby-on-rails-5.1

大家好,我尝试在rails 5.1中制作form_for时出错。

<%= form_for: @image do |f|%>
<p>
    <%= f.label :description %>
    <%= f.text_field :description %> <br>

    <%= f.submit %>
</p>
<% end %>

它抛出错误:

ImagesController#edit is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.

我在做新方法时遇到了同样的错误,我使用了解决它:

url: {action: "create"}

但在这种情况下是不同的,我做不到url: {action: "edit"} 这是我的路线。 http://localhost:3000/images/1/edit 这是我的控制者:

def edit
    @image = Image.find params[:id]     
end

请帮忙。

1 个答案:

答案 0 :(得分:0)

您有views/images/edit.html.erb的档案吗?它不一定是错误的。它只是告诉你,你还没有对这个行动发表看法。