ruby on rails - Mongoid embeds_one form_for path error for new objects -
can have same model class collection resource in 1 , singular resource in other?
update !!!
i think mongoid issue, editing existing photos works. new throw path errors
orm mongoid beta 20
routes.db
resources :products resources :photos collection post 'sort' end end end resources :companies resource :photo end
photos_controller.rb
before_filter find_or_build_photo
def find_or_build_photo # these have many photos if !params[:story_id].blank? or !params[:product_id].blank? @photo = params[:id] ? @parent.photos.find(params[:id]) : @parent.photos.build(params[:photo]) end # these have 1 photo if !params[:company_id].blank? @photo = @parent.photo ? @parent.photo : @parent.build_photo(params[:photo]) end end
i "undefined method photo_path" etc. errors in view form_for helper. theorie -> because there "photos"-controller , no "photo"-controller. confuses path-blackmagic!?
started "/companies/4cf6b9c3499dda12e3000003/photo/edit" 127.0.0.1 @ thu dec 02 17:51:42 +0100 2010 processing photoscontroller#edit html parameters: {"company_id"=>"4cf6b9c3499dda12e3000003"} mcu_dev['companies'].find({:_id=>bson::objectid('4cf6b9c3499dda12e3000003')}, {}).limit(-1) rendered photos/_form.html.haml (3893.3ms) rendered photos/edit.html.haml within layouts/application (3899.1ms) completed in 6730ms actionview::template::error (undefined method `company_photos_path' #<# <class:0x103842e30>:0x1038404a0>): 1: 2: 3: = form_for [@parent, @photo], :html => { :multipart => true } |f| 4: -if @photo.errors.any? 5: #errorexplanation 6: %h2= "#{pluralize(@photo.errors.count, "error")} prohibited photo being saved:" app/views/photos/_form.html.haml:3:in `_app_views_photos__form_html_haml___1111817113_2176907420_506750' app/views/photos/edit.html.haml:3:in `_app_views_photos_edit_html_haml__1185726823_2176970040_0' lib/include/flash_session_cookie_middleware.rb:16:in `call'
when debug it. instance variables set:
http://img4.imageshack.us/img4/6892/rubyerror.png
full source: github.com/banditj/mongoid-carrierwave-uploadify
try overriding url:
<%= form_for [@company, @photo], :url => company_photo_path(@company) |f| %> <% end %>
this ought give form posts photoscontroller#create. want put though, since controller picks photo if exists, in case need pass in :html => { :method => :put }
, should go photoscontroller#update.
Comments
Post a Comment