Ruby on rails Rails 3为多态关联的子模型创建表单
我的应用程序的route.rb文件包含以下命名空间:Ruby on rails Rails 3为多态关联的子模型创建表单,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我的应用程序的route.rb文件包含以下命名空间: namespace :admin do resources :index resources :posts do resources :images end resources :statics end 我使用多态关联 Post模型:有多个:图像,:as=>:imageable 图像模型:属于\u to:imageable,:多态=>true 我在
namespace :admin do
resources :index
resources :posts do
resources :images
end
resources :statics
end
我使用多态关联
Post模型:有多个:图像,:as=>:imageable
图像模型:属于\u to:imageable,:多态=>true
我在迁移中创建了必要的字段
当我调用@post.images时,没有错误消息,我认为这种关系很好。
我想,我的问题在于图像上传器表单,我使用的代码如下:post/edit操作
[there is post edit form]
<% form_tag admin_post_images_url( @post ) , :multipart => true do %>
<%= file_field :imageable, :photo, :size => 40 %>
<input type="submit" name="send" value="upload!" />
<% end %>
图像已成功上载,但未填充ImageTable\u id和\u类型。我认为管理员\发布\图片\ url@post部分有问题,问题出在哪里
更新:
当我添加manual来创建ImageTable_id和类型,并列出它的工作时,所以关联很好 试试这样的方法:
<% form_for([:admin, @post, @image], :multipart => true) do %>
这可能并不完全有效,但应该让您开始走上正确的道路。不管怎样,如果您使用的是模型,则需要表单,而不是表单标签。上传图像时通过的参数是什么?[1m[35mAREL 0.2ms[0m插入图片创建时间、图片文件名称、图片类型、图片id、图片内容类型、更新时间、图片文件大小、标题值“2011-07-09 18:20:36”、“屏幕截图2011-06-25于5.10.25 PM 2.png”、NULL、NULL、“图片/png”、“2011-07-09 18:20:36”、“266818、NULL我是指提交表单时传递的参数:参数:{:imageabletype=>}etc参数:{commit=>upload,imageable=>{photo=>},Authority_token=>JLmrKyDgP4WaZdfLpZIf6SpGCNUCEX52E7KVNEhtgVs=,utf8=>✓, post_id=>1}