ruby-on-rails-3.2

Unable to setup Rspec & Capybara in Rails 3.2

人盡茶涼 提交于 2019-12-01 03:07:56
问题 I am creating a sample application for rspec testing, and I followed the below steps In Gemfile: gem "rspec-rails", :group => [:test, :development] group :test do gem "factory_girl_rails" gem "capybara" gem "guard-rspec" end Then executed the below steps: bundle. rails g rspec:install. mkdir spec/support spec/models spec/routing. Added "require capybara/rspec" to my spec_helper file Created a sample test as below: require 'spec_helper' describe "Users" do describe " List users" do it "List

How to call methods defined in ApplicationController in models

六眼飞鱼酱① 提交于 2019-12-01 03:06:11
I have defined method in ApplicationController class ApplicationController < ActionController::Base helper_method :get_active_gateway def get_active_gateway(cart) cart.account.gateways end end When I am calling this method in model class Order < ActiveRecord::Base def transfer active= get_active_gateway(self.cart) end end It throwing error undefined local variable get_active_gateway . So I wrote class Order < ActiveRecord::Base def transfer active= ApplicationContoller.helpers.get_active_gateway(self.cart) end end Then it was throwing error undefined method nil for Nilclass . I am working in

ruby on rails how to deal with NaN

爷,独闯天下 提交于 2019-12-01 02:03:13
I have read few posts regarding NaN but did not figure out how to deal with it in Ruby on Rails. I want to check a value if it is a NaN I want to replace it with Zero(0). I tried the following logger.info(".is_a? Fixnum #{percent.is_a? Fixnum}") when percent has NaN it returns me false. I have made few changes in the logger logger.info("Fixnum #{percent.is_a? Fixnum} percent #{percent}") Output Fixnum false percent 94.44444444444444 Fixnum false percent NaN Fixnum false percent 87.0 NaN is instance of Float . Use Float#nan? method. >> nan = 0.0/0 # OR nan = Float::NAN => NaN >> nan.class =>

Sass::SyntaxError Undefined Variable [duplicate]

不羁岁月 提交于 2019-12-01 00:23:48
This question already has an answer here: False positive “undefined variable” error when compiling SCSS 4 answers I'm new to the Asset Pipeline, so let me know if I'm doing things wrong. Using Rails 3.2 with SASS. I have a configuration partial that defines a bunch of SASS variables that I want to use throughout my scss files. Per this guide , I import configuration first, then bonus . However, I keep getting a Sass::SyntaxError saying Undefined variable: "$darkRed" in bonus.css.scss. What am I doing wrong? application.css.scss /* * This is a manifest file that'll be compiled into application

How to do an Ajax GET request to get data from rails and pass it to javascript(google maps)?

微笑、不失礼 提交于 2019-12-01 00:05:25
I have a model Locations with two columns latitude and longitude. I want to find a way where I can get the list of locations and pass them to google maps using Ajax and javascript. So far my code is as follows: map.js: function initialize() { var map; var latlng = new google.maps.LatLng(37.09, -95.71); var options = { zoom: 5, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, disableDoubleClickZoom: true, noClear: true, navigationControl: true, navigationControlOptions: { position: google.maps.ControlPosition.TOP_RIGHT } }; map = new google.maps.Map(document

How to call methods defined in ApplicationController in models

谁说胖子不能爱 提交于 2019-12-01 00:01:00
问题 I have defined method in ApplicationController class ApplicationController < ActionController::Base helper_method :get_active_gateway def get_active_gateway(cart) cart.account.gateways end end When I am calling this method in model class Order < ActiveRecord::Base def transfer active= get_active_gateway(self.cart) end end It throwing error undefined local variable get_active_gateway . So I wrote class Order < ActiveRecord::Base def transfer active= ApplicationContoller.helpers.get_active

Set of CoffeeScript/JavaScript classes and methods available to rest of Rails app

流过昼夜 提交于 2019-11-30 21:56:03
I'm using Rails 3.2.9. When I add CoffeeScript code to a .js.coffee file in the /app/assets/javascripts directory, I get the resulting JavaScript in all of my webpages. The problem is all the JavaScript is wrapped in: (function() { // my code }).call(this); So any methods I define are not visible in any other CoffeeScript code I write in other files. What's the proper way to write a set of reusable CoffeeScript classes and methods with Rails? The simplest thing to do is to namespace all your classes. If your application is called "app" then in your initialization code before anything else

Sass::SyntaxError Undefined Variable [duplicate]

耗尽温柔 提交于 2019-11-30 20:34:37
问题 This question already has answers here : False positive “undefined variable” error when compiling SCSS (4 answers) Closed 3 years ago . I'm new to the Asset Pipeline, so let me know if I'm doing things wrong. Using Rails 3.2 with SASS. I have a configuration partial that defines a bunch of SASS variables that I want to use throughout my scss files. Per this guide, I import configuration first, then bonus . However, I keep getting a Sass::SyntaxError saying Undefined variable: "$darkRed" in

Database Cleaner not working in minitest rails

怎甘沉沦 提交于 2019-11-30 20:12:54
My Minitest controller tests are working fine if I run them alone using rake minitest:controllers but when I run rake minitest:all then I get validation failed error. It is because email is already used in model tests. I used DatabaseCleaner to clean the database but unable to clean database. My code for database cleaner: require "database_cleaner" DatabaseCleaner.strategy = :transaction class MiniTest::Rails::ActionController::TestCase include Devise::TestHelpers def setup DatabaseCleaner.start end def teardown DatabaseCleaner.clean end Short answer: gem install "minitest-around" Long answer:

Authlogic doesn't work with my Rails 3.2 app

最后都变了- 提交于 2019-11-30 20:12:34
I'm running Rails 3.2 and the latest version of Authlogic. When I run my app locally on my Mac, it works fine. When I try to run it on my production server (Ubuntu with Passenger/Apache), I get this: You must establish a database connection before using acts_as_authentic I'm not sure how to troubleshoot the problem. I posted this related question earlier today before I realized that the problem was broader than I thought. I figured out the problem. Look at this snippet from Authlogic's lib/authlogic/acts_as_authentic/base.rb : private def db_setup? begin column_names true rescue Exception