activeresource

Rails: Specifing params without value to link_to

这一生的挚爱 提交于 2020-01-30 06:36:51
问题 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 articles_path(:most_popular => true) # /articles?most_popular=true note: i'm using inherited_resources with has_scope 回答1: If you don't add a value to the parameters you will not be respecting the W3C standard, which mandates that the params section has

Rails: Specifing params without value to link_to

痞子三分冷 提交于 2020-01-30 06:35:08
问题 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 articles_path(:most_popular => true) # /articles?most_popular=true note: i'm using inherited_resources with has_scope 回答1: If you don't add a value to the parameters you will not be respecting the W3C standard, which mandates that the params section has

Remove .xml extension from ActiveResource request

僤鯓⒐⒋嵵緔 提交于 2020-01-29 06:07:03
问题 I am trying to use ActiveResource to consume xml data from a third party API. I can use the RESTClient app to successfully authenticate and make requests. I coded my app and when I make a request I get a 404 error. I added: ActiveResource::Base.logger = Logger.new(STDERR) to my development.rb file and figured out the problem. The API responds with xml data to requests that do NOT end in xml. EG, this works in RESTClient: https://api.example.com/contacts but ActiveResource is sending this

Active Resource return nil object

↘锁芯ラ 提交于 2020-01-24 20:04:54
问题 I try to use active resource with a server where I can see log. I request the server with a show on a order with xml. class Orders < ActiveResource::Base self.site = "http://"+Hello::Services.session.server+"/api/" self.element_name = "orders" self.format = ActiveResource::Formats::XmlFormat end o = Hello::Services::Orders.find(o.id) When I look what he returns he sends me the correct object in xml. but when I look what I receive with this: puts "====:" puts xml puts xml.inspect the second

Activeresource, updating and merging

半城伤御伤魂 提交于 2019-12-24 19:07:04
问题 I've run into a problem I'm not able to handle right now with an ActiveResource object that looks something like this: #<Settings:0x000000085fff48 @attributes= {"account_id"=>1, "created_at"=>"2012-01-10T14:54:36Z", "id"=>1, "settings_hash"=> #<Settings::SettingsHash:0x000000085ff250 @attributes= {"email_notices"=> #<Settings::SettingsHash::EmailNotices:0x0000000860c860 @attributes= {"none"=> ["none", "none"]}, @persisted=false, @prefix_options={}>, "permissions"=> #<Settings::SettingsHash:

rails routes with :id not working

邮差的信 提交于 2019-12-24 14:22:00
问题 I have a model called Schedule that belongs_to a project. A project has_one schedule. I am trying to follow CRUD conventions but having some difficult. I have a page that lists all the projects and has a link next to each project to create a schedule. I started out with the following in my route file: resources :schedules Here's the problem. In the url of the 'new schedule' page there needs to be an :id that refers to the project that the schedule belongs to, that way when the schedule is

Monkey patching ActiveResource::Errors

百般思念 提交于 2019-12-23 03:16:14
问题 I've come across an issue with ActiveResource that has been resolved and was trying to monkey patch it into my application without much luck. I've added a file in config/initializers/ containing the following: class ActiveResource::Errors < ActiveModel::Errors # https://github.com/rails/rails/commit/b09b2a8401c18d1efff21b3919ac280470a6eb8b def from_hash(messages, save_cache = false) clear unless save_cache messages.each do |(key,errors)| errors.each do |error| if @base.attributes.keys.include

Convert CamelCase xml/json to ruby named attributes with ActiveResource

夙愿已清 提交于 2019-12-22 17:40:26
问题 I'm using ActiveResource to consume a REST service. The xml from the service looks like: <Person> <FirstName>Kevin</FirstName> <LastName>Berridge</LastName> </Person> ActiveResource parses this just fine, but it uses the names verbatim. So the model class will look like: p = Person.find(1) p.FirstName p.LastName I would much prefer if this would follow the Ruby naming conventions and look like: p = Person.find(1) p.first_name p.last_name Does ActiveResource have a way to do this? Is there a

Consuming non-REST APIs in Rails with ActiveResource

柔情痞子 提交于 2019-12-20 10:56:39
问题 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 ActiveResource, but I'd be forced to rewrite almost all of ActiveResource's methods. Is there another, more polished way of achieving the same result, even using another (Ruby) framework? 回答1: I don't think there is a way to do this with ActiveResource, for

How do you log the URL ActiveResource uses?

南笙酒味 提交于 2019-12-20 10:37:44
问题 Rails ActiveResource is awesome ... except for one thing: as far as I can tell, there is no way to see what URL it is using behind the scenes. For instance, let's say I have an ActiveResource called Issue, for a webservice at myIssues.com/issues.xml. If I do: Issue.find(:all, :params => {:page => 2}) I would expect that ActiveResource would make a call to: myIssues.com/issues.xml?page=2 ... but I don't actually know that. For all I know, ActiveResource could have decided it doesn't like the