ruby on rails - undefined method for _path, but route exists -
i getting rails error when create new "car_image"... ajax response is
undefined method `car_image_path' #<carimage:0x007fdbb1b79258>
route defined
resources :car_images, :only => [:index, :create, :destroy]
rake routes
car_images /car_images(.:format) car_images#index post /car_images(.:format) car_images#create car_image delete /car_images/:id(.:format) car_images#destroy
however, route setup , can see when rake routes, not sure issue is. using route in model method:
class carimage < activerecord::base belongs_to :car attr_accessible :description, :image, :title, :car_id, :file mount_uploader :file, carimageuploader def to_jq_upload { "name" => read_attribute(:file), "size" => file.size, "url" => file.url, "thumbnail_url" => file.thumb.url, "delete_url" => car_image_path(:id => id), "delete_type" => "delete" } end end
what causing undefined method here? record save, error response...
since need link in model (which should not be), add inside:
delegate :url_helpers, to: 'rails.application.routes'
then replace:
car_image_path(:id => id)
with:
url_helpers.car_image_path(self)
Comments
Post a Comment