I am trying to integrate my rails app with Resque plugin but in the doc it is not given that where should I write the code and how to use that code when running application. May be it is not understandable for me.
It would be helpful for me if any one explain it with an example application.
Thanks in advance.
You just need add the gem in your config.gem 'resque'
After you can call by Resque.enqueue(xxx). All class call by Resque queue need to be load. You can add it on app/worker directory and add it in load_path. Or put in lib and use the autoloading stuff.
You could follow the steps as specified in the railscasts.
Related
I've got some helper code (monkey patches) I tend to carry around from rails project to rails project via simply copying files or pasting code into the initializers folder.
I think a clean way to deploy different categories of my initalizer code would be to simply add gems to my project Gemfile that would do the equivalent of this for me. I'm not very skilled at creating gems or the deeper side of ruby on rails engineering so I just wanted to know if this were possible before I got started with it.
Yes, this is definitely possible. It should be probably enough to make a simple gem, put your monkey-patches there and require them in the gem entry point (e.g., if the gem is called foobar, then bundler will require lib/foobar.rb by default).
There is a guide on creating gems available in Bundler docs. In case you need to interact with Rails application configuration, you can take a look at Rails Engines.
I am relatively new to web dev and I am trying to set up the ruby on rails gem ga_events (https://github.com/Nix-wie-weg/ga_events). I am doing this because I need to have google analytics event tracking within controllers and this gem seems like a good way to do it. The issue I am having is where the readme says, "After requiring ga_events.js, you have to choose an adapter." I am using Google Universal Analytics and thus I would like to choose that one. It doesn't say specifically how to do this. Where do I put that code block (https://github.com/Nix-wie-weg/ga_events#google-universal-analytics-analyticsjs)? Do I need to make a new file somewhere?
I'm assuming it's obvious for a more experienced developer. More detailed instructions+explanation would be really helpful. Thanks.
I'm using Rails 4.0.13 and Ruby 2.0.0p643.
I was having the same issue here! Turns out, it is just javascript code.
I put mine under application.js since it's a code that need to be on every page.
My setup: Rails 3.0.9, Ruby 1.9.2
I need to extend Active Merchant module to include my own code, I'm following the article here
http://blog.matthodan.com/how-to-add-support-for-paypal-website-payment
As per the article, I created paypal_recurring_payments.rb in /vendor/plugins/active_merchant/lib/active_merchant/billing/gateways/paypal/. Next I have to modify an Active Merchant gem file paypal.rb to add a line of code. The problem is that I can't deploy that code change to Heroku, so I need an alternate way of doing this. Any insights will be much appreciated.
Fork the gem on github
Make the appropriate change to your fork of the gem.
Reference your fork in the Gemfile using the :git option. See the docs for examples.
I would like to write my own gem that helps me in my rails apps. It will also inculde some controllers that deliver html. So i need to test that in a browser (html/css/js).
Whats the best practice for that?
Now im using the echoe gem to build my gem (are there any better gems?).
rake install
switch to other tab
stop the rails app
start the rails app (so it has loaded the gem)
and then testing it, in a browser with good old refresh.
This is no fun. Can i do it more efficient somehow? Is it insane not to write tests for the ruby files?
You could use two resources to help you:
https://github.com/krschacht/rails_3_engine_demo
https://github.com/josevalim/enginex
This will help you creating a gem which will basically be an engine (enabling controller and views). The first link as great and helpful documentation.
The main principle is to code in a separate folder and add your 'gem' in local by doing gem ‘cheese’, :path => "../rails_3_engine_demo"
Once you feel ready, pack it with jeweller or bundler. Here is another link: http://sirupsen.com/create-your-first-ruby-gem-and-release-it-to-gemcutter//
Including the gem this way in your app will enable you to properly test it's behaviour.
jeweler:Opinionated tool for creating and managing Rubygem projects
I'm having trouble getting rubygems to work in my Rails app. Specifically, I'm trying to use the json gem, documented here: http://flori.github.com/json/ I can successfully use JSON.parse() in IRB and script/console but not in my rails app.
I know it's some combination of config.gem 'json' in environment.rb and other things, but can't find a good explanation anywhere.
Can someone give me a concise list of what is required to use this gem OR point me towards comprehensive documentation of using gems in Rails? thanks!
config.gem is used for gem dependency in rails and it does nothing more than telling rails that a gem is needed, and helping the user install the appropriate gem, etc (more details here: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies)
however by installing a gem, it should be able to be used by the rails app automatically, if not, probably you can add require "json" into environment.rb or in an .rb files in the initializers folder?
Hope it helps =)
I solved it. There's decent documentation here: http://apidock.com/rails/Rails/Configuration/gem
Once you have used config.gem in environment.rb, you should not need to 'require' it later.
My problem was that I had not stopped and restarted the server! It worked in script/console because everything was getting reloaded every time.