# Activeresource problems

**URL:** <https://www.ruby-forum.com/t/activeresource-problems/130069>\
**Category:** Rails\
**Created:** [February 25, 2008, 5:50am UTC](https://www.ruby-forum.com/t/activeresource-problems/130069 "2008-02-25T05:50:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamwest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@adamwest](https://www.ruby-forum.com/u/adamwest)\
**Post date:** [February 25, 2008, 5:50am UTC](https://www.ruby-forum.com/t/activeresource-problems/130069/1 "2008-02-25T05:50:48Z")

</div>

I have been experimenting with active resource recently but came  
across a problem. I receive a 404 error when trying to create a new  
object. The prescription object belongs to a device object.

Processing PrescriptionsController#create (for 127.0.0.1 at 2008-02-24  
20:41:06) [POST]  
Session ID: 7bb36ceab59dfac446b7d21dd3c6a45e  
Parameters: {“format”=\>“xml”, “action”=\>“create”,  
“controller”=\>“prescriptions”, “prescription”=\>{“device\_id”=\>4,  
“count”=\>4}}

ActiveRecord::RecordNotFound (Couldn’t find Device without an ID):

I have an activeresource class definition that looks like

class Prescription \< ActiveResource::Base  
self.site = [http://www.WEBHOST.com](http://www.WEBHOST.com)’ #modified  
end

Then issue Prescription.create(:device\_id =\> 1, :count =\> 1) which  
raises the above error.  
Other class definitions work flawlessly. What might be going on?

---

<div class="post-metadata">

**Author:** ![adamwest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@adamwest](https://www.ruby-forum.com/u/adamwest)\
**Post date:** [February 25, 2008, 6:06am UTC](https://www.ruby-forum.com/t/activeresource-problems/130069/2 "2008-02-25T06:06:02Z")

</div>

after recreating the entire model step for with Rails project using  
the recomended nested resources method my project now looks like.

I am using nested resource defined in routes.rb  
map.resources :devices do |device|  
device.resources :prescriptions  
end

I define the network class definition for Prescription as

class Prescription \< WebResource  
self.site += “/devices/:device\_id/”  
end

This should allow for calls like  
Prescription.find(:all, :device\_id =\> 1) or  
Prescription.create(:device\_id =\> 1, :drug\_id =\> 4)

Unfortunatly it fails with a 404 error the log has  
ActionController::RoutingError (No route matches “/devices//  
prescriptions.xml” with {:method=\>:post}):

Why is the device\_id parameter not being passed?
