Testing function contains an API request

I'm trying to test my rails application which using Stripe APIs, So I started with models, I'm using Rspec, The model which i want to test is called bank_account.rb inside it there is a function called (create_bank_account) with argument (bank_token) its pseudocode is something like this:def create_bank_account(bank_token) # make a Stripe request and save it in local variable # save needed data in my bank_account table in my DBendwhen i started to test this function, I found that there is an API call inside it, Which is not good, I need my test not to depend on Internet, ...

multilevel caching with Ruby on Rails 3

I've searched about this question in many places, but haven't found answer.According to rails guides and similar materials about caching, rails can use one of such cache types: in-memory, file storage, memcached, custom cache classes, and so on.But what if I want to use two or three cache types in one application, depending on cached entity?For example (a high-load news agregator): I have a couple of front-end rails servers, couple of servers with sharded MongoDB and one server for memcached. What if I want to make per-node in-memory cache on front-ends for very often used...

How can I combine two arrays into one by a common attribute?

How can I combine two arrays into one so that for example...Day 1: Notes/formDay 2: Notes/formDay 3: Notes/formDay 4: Notes/formDay 5: Notes/formIf a user then creates a note on Day 3 it would look like...Day 1: Notes/formDay 2: Notes/formDay 3: Notes/notesDay 4: Notes/formDay 5: Notes/formThe code monstrosity below tried to achieve the above, but the iteration is all off. If for example a note is created on Day 1 and Day 3 then the output will look like...Day 1: Notes/notes # Shows both Day 1 and Day 3 note. Only want to show Day 1 noteDay 1: Notes/formDay 2: Notes/formDay...

Why do we prefix class variables with @@ in ruby?

I ran an experiment trying to understand how singletons work.I don't understand why we prefix class variables with @@ instead of @? As referenced below, if the variable is created inline with the class definition, self is defined as Test, and the variable is a class variable correct? We can then use attr_accessor in the singleton class definition to access it. The @var in initialize appears to be different because self is set to t in the context when it is initialized, so var belongs to t in that context?This is all very confusing, any help would be appreciated.class Test ...

Unexpected memcache GETs in rails 3.2 app

My rails 3.2 app is trying to fetch values from the cache (memcached via dalli) that I'm not expecting it to be caching. It's not getting any cache hits, but I'm puzzled about what is going on. This happens with config.action_controller.perform_caching = true on production as well as development, using WEBrick.Here's a snippet of what I'm seeing in memcache verbose output:<30 GET https://www.myrailsapp.com/?>30 Writing an error: Not found>30 Writing bin response:>30 0x81 0x00 0x00 0x00>30 0x00 0x00 0x00 0x01>30 0x00 0x00 0x00 0x09>30 0x00 0x00 0...

Fine Uploader — Upload failed in Rails

This problem occur in rails While uploading with fine-uploader, uploaded fine.but when finish uploading, it give me upload failed. But file is uploaded. My script is below.<script>(function() { $('#fine-uploader-gallery').fineUploader({ template: 'qq-template-gallery', request: { endpoint: '/admin/files/upload', params: { authenticity_token: "<%= form_authenticity_token %>" } }, failedUploadTextDisplay: { mode: 'custom' }, callbacks: { onComplete: f...

Auto-loading lib files in Rails 4

I use the following line in an initializer to autoload code in my /lib directory during development:config/initializers/custom.rb: RELOAD_LIBS = Dir[Rails.root + 'lib/**/*.rb'] if Rails.env.development?(from Rails 3 Quicktip: Auto reload lib folders in development mode)It works great, but it's too inefficient to use in production- Instead of loading libs on each request, I just want to load them on start up. The same blog has another article describing how to do this:config/application.rb: # Custom directories with classes and modules you want to be autoloadable.config.au...

Rails 3: I want to list all paths defined in my rails application

I want to list all defined helper path functions (that are created from routes) in my rails 3 application, if that is possible.Thanks, rake routesorbundle exec rake routes [XXX]UpdateI later found that, there is an official way to see all the routes besides going to a non-routed path. This is here http://localhost:3000/rails/info/routesThough, it may be late, But I love the error page which displays all the routes. I usually try to go at /routes (or some bogus) path directly from the browser. Rails server automatically gives me a routing error page as well as all the ...

Changing localhost site using /private/etc/hosts

I've got an app that interacts with facebook. That mean's I can't test things out on localhost:3000. To fix this, I changed the /private/etc/hosts file so it looks like this:127.0.0.1 localhost127.0.0.1 dev.example.comThis worked fine on my old computer, but not on my new one. Now, in order to get things working properly, I have to append the port number when I'm looking at the app in the browser.dev.example.com:3000I'm guessing this is an issue with the newer OS (mountain lion), but I'm not sure.Is there anyway to configure my hosts file so that I don't need ...

Rails fine-uploader icons can't show in browser give error without gems

In console screenshots is that, also in /assets/admin included images, and in fine-uploader-gallery.css included likebackground: url("edit.gif"); that. How we can fix this images or icons?I hope, explaining well. Thanks in advance change the file .css to .scss and use the syntax of scss: background: image-url("admin/edit.gif") no-repeat 0 0; [XXX]

Adding Hash parameter in the URL Rails Routes

How to add a hash parameter in link_to. I need to generate a URL something like this../p/generate/#sometextThis is how my code looks now.link_to "Click",my_pathHow to add the hash parameter to my routes method.Now for the answerWhen I posted the question, I didn't got through the url helpers API fully. http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_toI did now. :) .I found the answer.link_to "Click", my_path(:anchor => "sometext")M.cypher below almost got it. :) This is how you would usually do it:link_to "Click", my_path(:anchor =&...

Why do I get an error when starting ruby on rails app with mongrel_rails

Why do I get following error when trying to start a ruby on rails application with mongrel_rails start? C:\RailsTest\cookbook2>mongrel_rails start** WARNING: Win32 does not support daemon mode.** Daemonized, any open files are closed. Look at log/mongrel.pid and log/mongrel.log for info.** Starting Mongrel listening at 0.0.0.0:3000c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/tcphack.rb:12:in `initialize_without_backlog': Only one usage of each socket address (protocol/network address/port) is normally permitted. - bind(2) (Errno::EADDRINUS...

How to iterate over ActiveRecord model objects with a particular value of an attribute?

I am going to try to be very explicit because I've been trying to do a "special" iteration for several days.I created cards which are named hiragana and are defined by a Letter (A, E, I, O, U) and decline in (KA, SA, TA... KE, SE, TE... (I, O, U => similar)).I do an iteration with .each with hiragana instance to list them on the index page:<% @hiraganas.each do |hiragana| %> <li> <%= render 'allhiraganas', hiragana: hiragana %> </li><% end %>The view is <div class="row"> <ul class="list-inline text-center card-frame"> <l...

Bitnami Lime Survey and MS SQL

I'm trying to setup a Bitnami Limesurvey stack on my local and I've seen that it is running MySQL as its default DB.Question is Can I migrate this into MS SQL Database?Please feel free to comment, will be pretty much appreciated. Yes, Limesurvey supports multiple Databases.https://manual.limesurvey.org/Installation#Make_sure_you_can_use_LimeSurvey_on_your_websiteI believe you can migrate the DB and then just point the DB config to the new DB. [XXX]It might be easier to export the surveys as survey archives (.lsa and .lss), install a new LimeSurvey version on MSSQL and...

how to use Heroku's application database from another Heroku application

I have two Rails 3 applications currently running on Heroku. One is main application and another one is Forum for the main application.For both of these applications I want to use a single db table for users. For this reason, in Forum application I overwritten ActiveRecord db connection settings like this.# User model in Forum applicationclass User < ActiveRecord::Base establish_connection( :adapter => "postgres", :host => "ec2-XXX-XXX-XXX-XXX-XXX.compute-X.amazonaws.com", :username => "username", :password => "password", :database => ...

How to use Sprockets Rails plugin on Heroku?

I just deployed my Rails app to Heroku, but the Javascripts that were using Sprockets plugin don't work.I understood that, because my Heroku app is read-only, Sprockets won't work. I've found this sprockets_on_heroku plugin that should do the work, but I don't really get how to use it :I added config.gem sprockets in config/environment.rbI added sprockets in my .gems fileI pushed these on Heroku and Sprockets was successfully installedI locally ran script/plugin install git://github.com/jeffrydegrande/sprockets_on_heroku.git and the plugin was successfully installedNothing...

Page 1 of 493  |  Show More Pages:  Top Prev Next Last