{"id":2650,"date":"2022-08-30T15:26:38","date_gmt":"2022-08-30T15:26:38","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/problem-about-activeresource-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:38","modified_gmt":"2022-08-30T15:26:38","slug":"problem-about-activeresource-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-activeresource-collection-of-common-programming-errors\/","title":{"rendered":"problem about activeresource-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dd85c761c8d8adab6d2608ede23be346?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCarson Cole<br \/>\nruby-on-rails ruby-on-rails-3 activeresource<br \/>\nUsing ActiveResource and when I have a nested resource, using the &#8216;prefix&#8217; works great.class Account &lt; ActiveResource::Baseself.prefix = &#8220;\/users\/:user_id\/&#8221; endAll is fine as long as :user_id has been defined, or else an error will be raised. But how to make the &#8216;self.prefix&#8217; conditional, in cases where I don&#8217;t want to access this resource as a nested resource, but rather as the resource itself? For example, I&#8217;d like to retrieve all accounts, not just the accounts scoped by a particular user?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aeb0552279d07ef79b82de287e55b4d5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSainath Mallidi<br \/>\nruby-on-rails activerecord activeresource<br \/>\nI am stuck on how to set the site variable to ActiveResource at runtime, I read this post which explains how to do the samehttp:\/\/blog.rubybestpractices.com\/posts\/gregory\/rails_modularity_1.htmlBut the only problem there is the mapping from service name to url is predefined. In my case its the same service except in different domain and return identical results.domain1.mydomain.com domain2.mydomain.comThis active resource belongs to another active record model and which domain to access depends<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/graph.facebook.com\/616243351\/picture?type=large\" \/><br \/>\nAaron Mcguire<br \/>\nruby rubygems gem activeresource ruby-2.0<br \/>\nI have a gem I&#8217;ve created ( https:\/\/github.com\/samcreate\/Simon ) that doesn&#8217;t work with ruby-2.0.0-p247 (works fine in 1.9.3). I get two errors that I&#8217;ve found very little help with &#8211;by my own searching abilities. Below is the error stack but I&#8217;ve added a little detail each error to show some of my own findings.simon create \/Users\/aaron.mcguire\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/commander-4.1.3\/lib\/commander\/runner.rb:365:in `block in require_program&#8217;: program version required (Commander::Runner::C<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bf46f05f9be401f6009db179423767bc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSteve Wright<br \/>\nruby-on-rails rest ruby-on-rails-3 activeresource<br \/>\nI have a REST API that I am trying to access using Rails 3.0.1 that returns:&lt;Sessions&gt;&lt;Session&gt;&lt;Title&gt;This is a sample title&lt;\/Title&gt;&#8230;Misc&lt;\/Session&gt;&lt;Session&gt;&lt;Title&gt;Another Title&lt;\/Title&gt;&#8230;Misc&lt;\/Session&gt; &lt;\/Sessions&gt;I have set up my session.rb class defined:class Session &lt; ActiveResource::Baseself.site = &#8220;http:\/\/example.com\/rest&#8221; endThe url that will return the XML is http:\/\/example.com\/rest\/sessions.I then have a controller that is d<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/56de7700298f470227990ba23202e6a4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nere<br \/>\nruby-on-rails ruby-on-rails-3 json activeresource freebase<br \/>\nI&#8217;ve got ActiveResource setup to consume the freebase api in json, and it should work fine except that the json freebase returns causes ActiveResource to blowup.NoMethodError: undefined method `collect!&#8217; for #&lt;Hash:0x007fd674831dd0&gt;How can I define a custom json parser to fix whatever is wrong?class Freebase &lt; ActiveResource::Baseself.site = &#8220;https:\/\/www.googleapis.com\/&#8221;self.format = :jsondef self.search(word)self.find(:all, :from =&gt; &#8220;\/freebase\/v1\/search\/&#8221;, :params =&gt; { :query =&amp;g<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0b97f04b6108375f11ad30a42224d745?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncodinghands<br \/>\nruby-on-rails shopify activeresource<br \/>\nI&#8217;m unable to add &#8216;new&#8217; RESTful entities without defining a schema in my RoR ActiveResource model, even though I&#8217;ve read this is optional. When omitting the schema (I&#8217;ve included it in the code below for clarity), I receive the following error:NoMethodError in Pages#newundefined method `author&#8217; for #&lt;Page:0x4823dd8&gt;When I include the scheme, everything works as expected. I&#8217;d really rather not have to keep track of the schema every time it changes, and I&#8217;ve seen examples that don&#8217;t require<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1ea215872ccae10c90c25905859debe5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMuflix<br \/>\nruby-on-rails activeresource<br \/>\nI have database table storemodel name models\/store\/store.rbclass Store::Store &lt; ActiveRecord::Base &#8230; endcontroller controllers\/store\/maintenance_controller.rbclass Store::MaintenanceController &lt; ApplicationControllerdef index@stores = Store.allrespond_to do |format|format.html # index.html.erbformat.json { render json: @stores }endenddef new@store = Store.newrespond_to do |format|format.html # new.html.erbformat.json { render json: @store }endendroutes.rbnamespace :store doroot :to =&gt;<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/56de7700298f470227990ba23202e6a4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nere<br \/>\nruby-on-rails ruby-on-rails-3 rest activeresource freebase<br \/>\nI&#8217;m trying to get activeresource (on Rails 3.2) working with the Freebase API and I haven&#8217;t had much luck yet. How can I debug rails to see what&#8217;s going on and make sure the request is well formed?I think the suffixed .json is causing the failure but I don&#8217;t know how to check what&#8217;s going on?Error:ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found.Code:class Freebase &lt; ActiveResource::Baseclass &lt;&lt; self # also tried without this, same resultdef<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8d24aa67d897b1505392a31b21308e3c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKL-7<br \/>\nruby activeresource highrise<br \/>\nI am building a sinatra app that will use Highrise CRM gem to access Highrise data. This gem is based on ActiveResource class. I want to set site, user fields for every request. I followed suggestion posted here &#8211; Is it thread safe to set Active Resource HTTP authentication on a per-user basis?. I add code (shown below) and I get an error. Can anyone help understand this error and how to fix it. class ActiveResource::Baseclass &lt;&lt; self%w(site user).each do |attr| define_method<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dea9690ed3ccc6bca2289d60b2422ebd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOVERTONE<br \/>\nruby-on-rails ruby oop activerecord activeresource<br \/>\nSo I come from a background in Java where you can create a class as such.TestClass x = new TextClass();and call its method like x.shout();I&#8217;m attempting to do something similar in ruby with no such look. This could be syntactical or it could be I don&#8217;t understand the concept of ruby and rails well.So heres a class on a server in Rubyclass myResource&lt; ActiveResource::Baseself.site = &#8220;http:\/\/localhost:3008&#8243;def self.shoutputs &#8220;I AM AN ACTIVE RESOURCE SHOUT!&#8221;puts &#8221; CAPS RAGE YEAH!&#8221;puts Time.nowen<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6077701cc4f0c73314d8015200202eb2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser2122528<br \/>\nruby ruby-on-rails-3 api openssl activeresource<br \/>\nI have two rails apps running on different ports. From one app I am trying to consume the API of the other app. Here&#8217;s the code for Product.rb model in APP_1. class Product &lt; ActiveResource::Baseself.site = &#8220;https:\/\/localhost:3000&#8243;self.ssl_options = {:cert =&gt; OpenSSL::X509::Certificate.new(File.open(pem_file)),:key =&gt; OpenSSL::PKey::RSA.new(File.open(pem_file)),:ca_path =&gt; &#8220;\/path\/to\/OpenSSL\/formatted\/CA_Certs&#8221;,:verify_mode =&gt; OpenSSL::SSL::VERIFY_PEER} endI<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bcb6acc9d0d9bef99e033b36c3d32ca9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCharlie Somerville<br \/>\nruby-on-rails routing activeresource<br \/>\nI 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 doresources :threads doresources :repliesend endThat doesn&#8217;t work:Routing ErrorNo route matches {:action=&gt;&#8221;new&#8221;, :controller=&gt;&#8221;support\/replies&#8221;}If I remove the url: key from my form_for, I just get a NoMethodError when the form helper tries to call an undefined path helper method:I get the same Routing Error even when I remove the :support symbol f<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a39ae7e80e45b9129d82782c52aa4a3a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncwadding<br \/>\nruby activeresource<br \/>\nThis seems like a simple problem but I can&#8217;t seem to find the answer. I have a UTC time (ie. 1323481111) and I want to change it to a DateTime or TimeWithZone object in a ruby script. I haven&#8217;t found a way to do it with just ruby but I believe there should be a way to do it using ActiveSupport. It seems to me that I should be able to do it as follows:require &#8220;active_support\/all&#8221;Time.zone.at(1323481111)http:\/\/api.rubyonrails.org\/classes\/ActiveSupport\/TimeZone.htmlBut that doesn&#8217;t seem to work. An<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ab074ca0a48f06ab110c374fc7db258e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKir<br \/>\nruby api activeresource basecamp<br \/>\nMy code:require &#8216;rubygems&#8217; require &#8216;basecamp&#8217; basecamp = Basecamp.establish_connection!(&#8216;example.basecamphq.com&#8217;, &#8216;example&#8217;, &#8216;123456&#8217;, true) projects = Basecamp::Project.find(:all) projects.inspectIt gives:\/Users\/kir\/.rvm\/gems\/ruby-1.8.7-p352@project\/gems\/activeresource-3.1.0\/lib\/active_resource\/base.rb:922:in `instantiate_collection&#8217;: undefined method `collect!&#8217; for #&lt;Hash:0x105faa450&gt; (NoMethodError)from \/Users\/kir\/.rvm\/gems\/ruby-1.8.7-p352@project\/gems\/activeresource-3.1.0\/lib\/active_re<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dea9690ed3ccc6bca2289d60b2422ebd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOVERTONE<br \/>\nruby-on-rails ruby activerecord methods activeresource<br \/>\nSo continuing on my adventure of active resource and active record I&#8217;m trying to do a simple get method within an active resource but everytime I try to reference the variable, It throws a method undefined exception. Perhaps Its better to explain it in code.class UserRequest &lt; ActiveResource::Baseself.site = &#8220;http:\/\/localhost:3008&#8243;def get_status puts self.statusreturn self.statusendThe active record on the other side is made up of of URL, depth and status. So i go through the console as one w<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/83951c0a9a5ddaee9c13563bc6137bd2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJones Agyemang<br \/>\nruby-on-rails ruby callback mongoid activeresource<br \/>\nGetting an obscure error which originates from the ActiveResource standard Rails library. The line within Rails causing this problem is given below along with the output. Any idea on how to resolve this problem please?class Search &lt; ActiveResource::Nestful::Baseself.collection_name = &#8220;search&#8221;schema dostring :typeobject :eventenddef self.query(params)find(:all, :params =&gt; params) enddef self.per_page3 enddef recordattributes[attributes[&#8220;type&#8221;]] end endOUTPUTStarted GET &#8220;\/search?utf8=%E2%9C%<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d329252f2d857e941f48acc5ebf113d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\naletapool<br \/>\nruby activeresource<br \/>\nWhat I am missing? I am trying to use a rest service for with Active resource, I have the following:class User &lt; ActiveResource::Baseself.site = &#8220;http:\/\/localhost:3000\/&#8221;self.element_name = &#8220;users&#8221;self.format = :json enduser = User.new(:name =&gt; &#8220;Test&#8221;,:email =&gt; &#8220;test.user@domain.com&#8221;)p user if user.saveputs &#8220;success: #{user.uuid}&#8221; elseputs &#8220;error: #{user.errors.full_messages.to_sentence}&#8221; endAnd the following output for the user: #&lt;User:0x1011a2d20 @prefix_options={}, @attributes={&#8220;n<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0b6d61237c6bd92d14ed7d7deb2f9851?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKrista<br \/>\nruby-on-rails activerecord logging ruby-on-rails-3.1 activeresource<br \/>\nSo I have an application that earlier did not need ActiveRecord &#8211; thus we removed ActiveRecord from the application and formatted our logging as such:In application.rb:class DreamLogFormatter &lt; Logger::FormatterSEVERITY_TO_COLOR_MAP = {&#8216;DEBUG&#8217;=&gt;&#8217;32&#8217;, &#8216;INFO&#8217;=&gt;&#8217;0;37&#8217;, &#8216;WARN&#8217;=&gt;&#8217;35&#8217;, &#8216;ERROR&#8217;=&gt;&#8217;31&#8217;, &#8216;FATAL&#8217;=&gt;&#8217;31&#8217;, &#8216;UNKNOWN&#8217;=&gt;&#8217;37&#8217;}def call(severity, time, progname, msg)color = SEVERITY_TO_COLOR_MAP[severity]&#8221;\\033[0;37m[%s] \\033[#{color}m%5s &#8211; %s\\033[0m\\n&#8221; % [time.to_s(:short), s<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/51c6697964956c0c4bb136c84bdecd4d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRob Conery<br \/>\nruby-on-rails xml-rpc activeresource<br \/>\nI&#8217;ve seen a ton of examples with ActionWebService and XMLRPC, but they&#8217;re 3 years old and from what I understand, ActiveResource is supposed to replace ActionWebService.I&#8217;m familiar with how ActiveResource can use XML to &#8220;talk&#8221; to other web sites and consume model information, but XML-RPC is a whole different type of thing, wherein you pass the name of the method you want to execute and the request is handed off, etc.EDIT &#8211; I know how ActiveResource is supposed to work &#8211; but I have a client app<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cb9b44494bef86a37a8ff2c4f17b7f76?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njurer<br \/>\nruby-on-rails ruby client-server activeresource has-and-belongs-to-many<br \/>\nOn my server, I have two models:Broadcastclass Broadcast &lt; ActiveRecord::Basevalidates_presence_of :contentbelongs_to :userhas_and_belongs_to_many :feedsattr_accessible :content, :feeds, :feeds_attributesendFeedclass Feed &lt; ActiveRecord::Basehas_and_belongs_to_many :broadcastsattr_accessible :name endOn my client, I have basic ActiveResource classes for those models.When I try to create new Broadcast with given Feeds (from client):feed = Feed.find(3) &lt;-succesfulbroadcast = Broadcast.new<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2014-02-04 12:12:39. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Carson Cole ruby-on-rails ruby-on-rails-3 activeresource Using ActiveResource and when I have a nested resource, using the &#8216;prefix&#8217; works great.class Account &lt; ActiveResource::Baseself.prefix = &#8220;\/users\/:user_id\/&#8221; endAll is fine as long as :user_id has been defined, or else an error will be raised. But how to make the &#8216;self.prefix&#8217; conditional, in cases where I don&#8217;t want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2650","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2650"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2650\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}