I encountered strange problem - when Im trying to get User information from SalesForce using databasedotcom gem like this:
owner = client.find("User", deal_from_sf.OwnerId)
I get ActiveRecord error ActiveRecord::RecordNotFound for User, id:0013000000XXXXX
How can I use this method without patching native gem (as I understand alias for find method will help)?
The answer is so simple - read the documentation!!!
The problem obviously was in the namespace which was Global by default and User treated like ActiveRecord model. But one should add just one line to salesforce.yml file:
sobject_module : YourModuleName
and specify module where your salesForce logic lives)
http://rubydoc.info/github/heroku/databasedotcom/master/Databasedotcom/Client#sobject_module-instance_method
Related
I am following the documentation (http://amazon.rubyforge.org/) to try to begin working on S3 into my application (for serving files to the end user) but I keep running into errors.
Here is my Model:
class File < AWS::S3::S3Object
set_current_bucket_to 'test-bucket'
end
This is what I am trying via the Rails Console:
File.find 'test.pdf'
But I keep getting this error:
undefined method `find' for File:Class
Not sure what I am doing wrong here... anyone else run into this issue?
File is not a very good name for your model as it gets overwrited by Ruby's standart class File (docs). Just choose another name and everything will just work!
Here is the spec I am trying to get to pass:
context "when validating format of attributes" do
it { should validate_numericality_of(:price).greater_than_or_equal_to(0.01) }
end
I have rspec and shoulda-matchers installed. But I am getting undefined methodgreater_than_or_equal_to'`
Now that method isn't in the documentation but it does exist here:
https://github.com/moffff/shoulda-matchers/commit/7da06487d25c27d59d11fb7f2962e7ff345e45c4
So why is this not working? What should I do to get it to work?
The method does not exists in original thoughtbot/shoulda-matchers that is in you app. The version you're referring is a fork of original gem.
You can use this gem instead of original one, just set it source in Gemfile
gem 'shoulda-matchers', :git => 'https://github.com/moffff/shoulda-matchers.git'
But you should understand that forked and modified version can work unstable, does not include latest updates and fixes, and so on.
It must be is_greater_than_or_equal_to (with a is_ prefix), not greater_than_or_equal_to.
See the docs: https://matchers.shoulda.io/docs/v4.1.2/Shoulda/Matchers/ActiveModel.html#validate_numericality_of-instance_method
I feel like this should be a simple problem, but I'm pulling my hair out trying to track it down. I'm installed the chargify_api_ares gem, but can't do even basic things such as
Chargify::Subscription.create
As I get this path error. I feel like this must be a gem issue somehow but don't know where to go from here.
UPDATE: bundle show chargify_api_ares shows the correct path, I just somehow can't access it. Still trying random environment related things.
Looks like this is the source of the problem, in active_resource\base.rb:
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>)
# This method is regenerated at runtime based on what the \prefix is set to.
def prefix(options={})
default = site.path
default << '/' unless default[-1..-1] == '/'
# generate the actual method based on the current site path
self.prefix = default
prefix(options)
end
As I understand it, Chargify.subdomain should be setting the site.path, but I don't understand activeresource well enough yet to know what's happening and will continue to dig.
I too had the same issue.
I executed the following on the console
Chargify.configure do |c|
c.api_key = "<<api_key>>"
c.subdomain = "<<subdomain>>"
end
After that performing any Chargify console commands went through fine.
This is the query generated by Mongomapper:
MONGODB mydatabase['users'].find({:name=>"bob"}).limit(-1)
But this is not valid in the mongo console since the correct syntax is
db.users.find({:name=>"bob"}).limit(-1)
If I just use the generated one, I got this error in the console
Thu Jan 12 03:01:23 ReferenceError: mydatabase is not defined (shell):1
Is there any way to make it correct? This causes my rails application broken.
You can't use symbols in the MongoDB console as they are ruby and not javascript :-) Try this:
db.users.find({name: "bob"}).limit(-1)
It is not mongodb's issue. 406 is pretty much relating to the controller call.
I need to use:
render :json => #user
rather than
respond_to
I am using Rails 3 and AJAX and have a parent object which is being created through and AJAX request. This parent is sent with children and saves them all. However, if a child has an error, Rails will stop the request. Is there any way to tell Rails to ignore this? I understand the proper thing to do is find the problem within the Javascript sending the request and fix it. However, for the sake of learning, is there a way to tell Rails that some errors might be ignorable?
To save without validating use:
#parent.save(:validate => false)
Also, don't forget you can create conditional validation rules if needs be. For example, add a virtual attribute (an instance variable that is not persisted to the DB) accessible via bare_bones?. Then modify a validator like so:
validates_presence_of :nickname, :unless => "bare_bones?"
Then, in your controller you would do something like this:
#parent = Parent.new params[:parent]
#parent.bare_bones = true
#parent.save()
Hope this helps.
You are looking for exception handling.
begin
#code that may contain errors
rescue
#what to do if an error is encountered
end