Questions tagged [activeresource]

ActiveResource is the main class for mapping RESTful resources as models in a Rails application

Active Resource objects represent your RESTful resources as manipulatable Ruby objects. To map resources to Ruby objects, Active Resource only needs a class name that corresponds to the resource name (e.g., the class Person maps to the resources people, very similarly to Active Record) and a site value, which holds the URI of the resources.

355 questions
4
votes
1 answer

How to change request url structure in activeresource ruby gem

Is there a configuration option avilable in ActiveResource to change the request url structure for example when my client application try to access services of particular user from the api, ActiveResource sending request to api url in the following…
4
votes
1 answer

ransack gem, ActiveResource and REST API

I want to query to a rest api, passing paramateres in the link like ransack gem. Is there any way to integrate the ransack gem, quering through a rails client (with activeresource) to a REST API? I didn't find any manual about this.
4
votes
0 answers

ActiveResource and json root element

In ActiveResource 4.0.0 I need to have explicit "include_root_in_json = true" like this: class Base < ActiveResource::Base self.include_root_in_json = true end Why this is not default since Rails 4.0.0 need root element for saving objects by…
boblin
  • 3,541
  • 4
  • 25
  • 29
4
votes
3 answers

Rails: Specifing params without value to link_to

Supposing the route map.resources :articles how do you get this /articles?most_popular using link_to method? tried the following: link_to articles_path(:most_popular) # exception link_to articles_path(:most_popular => nil) # /articles link_to…
knoopx
  • 17,089
  • 7
  • 36
  • 41
4
votes
2 answers

How should look link the json response so that ActiveResource may generate a DateTime object from a date?

I have a question object with a created_at attribute in it. When I will find a question i get back the created_at from the REST service, but Activeresource do not convert the date string to…
Piioo
  • 759
  • 10
  • 24
4
votes
1 answer

uninitialized constant ::ActiveResource

I try to call an API. I just want use active resource so I make this code in a simple file .rb: class Order < ActiveResource::Base self.site = "http://localhost:3000/api/" self.element_name = "order" self.format =…
Guillaume
  • 335
  • 2
  • 4
  • 16
4
votes
3 answers

Consuming non-REST APIs in Rails with ActiveResource

I'm writing a client that consumes a non-REST API (i.e. GET site.com/gettreasurehunts), which requires that I specify all parameters (even the resource ID) in the request's HTTP body as a custom XML document. I'd like to use Rails and…
asymmetric
  • 3,800
  • 3
  • 34
  • 52
4
votes
2 answers

Rails: Run initializer before creating classes

Basically I have an initializer class at RAILS_ROOT/config/initialiers/app_constant.rb to make everything easy to control. class AppConstant APIURL = 'http://path.to.api' end And in the RAILS_ROOT/model/user.rb, I have the settings: class User <…
jwall
  • 759
  • 1
  • 8
  • 17
4
votes
1 answer

Why does activeresource.rb just call active_resource.rb?

Here are the entire contents of activeresource.rb: require 'active_resource' Could someone explain the logic of this? Why not simply have activeresource.rb contain what active_resource.rb contains and forget about the additional require statement?
monkeyman
  • 257
  • 2
  • 7
3
votes
2 answers

Return error message in XML response

I am working on the API of my web app. It is a Rails 2 app, and the REST API respond to XML. For example, I need to return an error, in case it wasn't able to unsubscribe a contact from a list. So I respond with an Unprocessable Entity (422), with…
pedroaxl
  • 293
  • 1
  • 3
  • 7
3
votes
1 answer

Why is ActiveResource returning Arrays of Hashes instead of objects?

I've just started building an api and application that consumes from the api using ActiveResource. I'll get into specifics with an edit, but my initial problem is this: I have a controller that does Resource.find(resource.id), that will return an…
blueblank
  • 4,724
  • 9
  • 48
  • 73
3
votes
1 answer

Rails nested resources within a namespace

I have this in my view: form_for [:support, @thread, @reply], url: support_thread_replies_path do |f| And this in my routes.rb: namespace :support do resources :threads do resources :replies end end That doesn't work: Routing Error No…
user47322
3
votes
1 answer

Map accessor method on activerecord to attribute on activeresource?

Some of attributes specified in ActiveModel are non db attributes which are just defined as getter setter. Problem is that these attributes values are not reflected on activeresource record on client side. #server side code class Item <…
Maddy.Shik
  • 6,609
  • 18
  • 69
  • 98
3
votes
0 answers

ArgumentError: expected attributes to be able to convert to Hash, got []

I got this error in active-resource using grape gem with an entity. I got this result on the…
Dipali Nagrale
  • 510
  • 5
  • 17
3
votes
1 answer

Bulk API calls in Rails

I have two different Rails application speaking with each other through API calls. Gone were the days where the call was light, meaning there was much less data transfer. We never cared about the HTTP request/response timeout issues. But once the…
bragboy
  • 34,892
  • 30
  • 114
  • 171