【发布时间】:2012-04-27 07:26:18
【问题描述】:
我有 Picture 模型,它包含 2 个字段 照片和描述(照片是来自 papperclip gem 的字段)
我有 PicturesController 包含新的创建编辑更新销毁和显示
我已经使用resource :pictures 在routes.rb 中声明,并且有我的路线。
pictures POST /pictures(.:format) pictures#create
new_pictures GET /pictures/new(.:format) pictures#new
edit_pictures GET /pictures/edit(.:format) pictures#edit
GET /pictures(.:format) pictures#show
PUT /pictures(.:format) pictures#update
DELETE /pictures(.:format) pictures#destroy
有我的查看代码
# pictures/new.html.erb & pictures/edit.html.erb
<%= form_for @picture, :html => {:multipart => true} do |f| %>
<div><%= f.label :photo %><br/>
<%= f.file_field :photo %></div><br/>
<div><%= f.label :description %><br/>
<%= f.text_area :description %></div><br/>
<%= f.submit :upload %>
<% end %>
#
我在新建和编辑中使用相同的代码,只是更改提交按钮标签。
new.html.erb 工作正常(创建图片并将其保存到数据库中)。
但错误出现在edit.html.erb
undefined method `picture_path' for #<#<Class:0x007f830e93ad30>:0x007f830e92d5b8>
我已经检查了@picture。为什么 rails 找不到 Picture 类的更新路径?
我遵循这个link 的form_for 指南。
有什么想法吗?谢谢。
【问题讨论】:
-
请添加
new和edit操作的代码。 -
@Thilo 问题出在我的路线上。谢谢你的答案。 :)
标签: ruby-on-rails paperclip ruby-on-rails-3.2