0

I am newbie to the rails world and in my project we have following model on server side

        class Server < ActiveRecord::Base
             has_many :disks, :dependent => :destroy
            accepts_nested_attributes_for :disks, :reject_if => lambda { |a| a[:size].blank? }, :allow_destroy => true
 end

       class ServersController < ApplicationController
        def new
          @server = Server.new
          4.times { @server.disks.build }     
          respond_to do |format|
          format.xml { render :xml => @server.to_xml(:include => :disks) }
          format.json { render :json => @server.to_json(:include => :disks) }
          end
        end
     end

and

class Disk < ActiveRecord::Base
  belongs_to :server
  validates :size, presence: true

end

On Client Side we have

class Server < ActiveResource::Base
  self.site = URLS_CONFIG['server_url']
  self.format = :json
  self.include_root_in_json = true 
end

and

class Disk < ActiveResource::Base
  self.site = URLS_CONFIG['server_url']
  self.prefix = "/servers/:server_id/"
  self.format = :json
end

When I try

disk1 = @server.disks.build

On client side it gave error

ActiveResource::ResourceNotFound: Failed.  Response code = 404.  Response message = Not Found.
    from /usr/local/bundle/gems/activeresource-4.0.0/lib/active_resource/connection.rb:144:in `handle_response'
    from /usr/local/bundle/gems/activeresource-4.0.0/lib/active_resource/connection.rb:123:in `request'

When I checked on server side the error was

ActionController::RoutingError (No route matches [GET] "/servers/disks/new.json"):
11:21:06 web.1    |   actionpack (4.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
11:21:06 web.1    |   web-console (2.1.3) lib/web_console/middleware.rb:29:in `call'
11:21:06 web.1    |   actionpack (4.2.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
11:21:06 web.1    |   railties (4.2.2) lib/rails/rack/logger.rb:38:in `call_app'
11:21:06 web.1    |   railties (4.2.2) lib/rails/rack/logger.rb:22:in `call

Can anyone tell me what went wrong here ? I wanted to show all disks for the server on the front end and allow user to edit and update it.

Anupam K
  • 309
  • 1
  • 4
  • 17

0 Answers0