Tag: ruby on rails 3.1

ActiveRecord :: ConnectionTimeoutError偶尔发生

每当我有一个使用ActiveRecord的应用程序时,我得到这个ConnectionTimeoutError – 但总是在一段未知的时间之后 ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5 seconds. The max pool size is currently 30; consider increasing it.): 它之前设置为5,我们已经增加了它,并且它无法同时使用30个连接。 我们唯一使用ActiveRecord的是会话存储。 我们的database.yml文件如下所示: development: adapter: sqlite3 database: db/development.sqlite3 pool: 30 timeout: 5000 (测试和生产设置相同) 我一直在谷歌搜索这个事件,刚刚发现这个post: https://groups.google.com/forum/#!msg/copenhagen-ruby-user-group/GEHgi_WudmM/gnCiwWqmVfMJ 哪个提到ActiveRecord一旦完成它就不会检查连接回池? 真的吗? 我是否需要手动管理连接? 我很感激任何建议!! 编辑我应该提一下我正在运行Rails 3.1.3

使用Rails 3.1的资产管道预编译.scss清单文件

Rails 3.1的发布版本在预编译带有扩展名scss的sass清单文件时遇到了一些奇怪的问题。 奇怪的是,默认的清单文件application.scss编译得很好,我在public/assets/下看到它。 但是,当我尝试编译自定义清单文件时,不会创建任何内容。 我在生产配置中启用了预编译选项。 config.assets.precompile += %w( user.scss admin.scss ) 就我所知,我正在正确运行预编译rake任务。 rake assets:precompile RAILS_ENV=production 也许这会有所帮助。 当我使用扩展名css而不是scss创建两个新的清单文件并且需要其中的原始scss文件时,这些新的清单文件将得到尊重并正确编译。 为什么application.scss得到这种特殊处理而不是其他sass清单文件?

将ActionView :: Helpers :: FormBuilder传递给部分

鉴于某个AJAX请求,我正试图以动态创建表单元素。 这是我的设置: 视图: true %> 控制器: def check_unique_id @student = Student.new @this_form = ActionView::Helpers::FormBuilder.new(:student, @student, @template, {}, proc{}) end JS: jQuery(“#guardian_student_details”).html(” “student_details”, :locals => { :s => @this_form }) %>”); 部分: 出于调试目的,我在部分的开头放置了以下行: 打印出: ActionView::Helpers::FormBuilder Student 这应该工作。 但是rails会出现以下错误: ActionView::Template::Error (undefined method `text_field’ for nil:NilClass): 1: 2: 3: ‘text_input is_empty’ %> 4: * 5: 6: app / […]

如何将序列添加到迁移并在模型中使用它们?

我希望拥有一个普通主键的“ Customer ”模型和另一个存储自定义“客户编号”的列。 另外,我希望db处理默认的客户编号。 我认为,定义序列是最好的方法。 我使用PostgreSQL。 看看我的迁移: class CreateAccountsCustomers true t.integer :salutation, :limit => 1 t.string :cp_name_1 t.string :cp_name_2 t.string :cp_name_3 t.string :cp_name_4 t.string :name_first, :limit => 55 t.string :name_last, :limit => 55 t.timestamps end say “Adding NEXTVAL(‘customer_no_seq’) to column cust_id” execute “ALTER TABLE accounts_customers ALTER COLUMN customer_no SET DEFAULT NEXTVAL(‘customer_no_seq’);” end def down drop_table […]

在Heroku上每分钟安排一个工作Rails 3.1

我想在Heroku上每分钟运行一个任务来检查是否满足条件以超时某些用户任务。 我每小时只能运行一次Heroku cron作业,那么设置这样的定时任务的最佳方法是什么。 我在Heroku上使用Rails 3.1。

渲染部分资产

我正在使用Ruby on Rails 3.1,我想知道如何在javascript资产中渲染部分内容。 我的目标是: # in /app/assets/javascript/cart.js.coffee.erb $(‘a.add_sth’).click -> $(‘.random_container’).append(”) 这会导致NoMethodError: undefined method `render’ for #<#:0x007fc5474cd470> 如果我写而不是它工作正常,顺便说一句。 我认为问题是资产管道独立于默认的ActionView,这就是为什么render()在那里是未知的。 无论如何,有没有办法让部分内容呈现?

omn​​iauth OAuthException&OAuth ::未经授权

我已经安装了omniauth 1.0。 我也有oauth-0.4.5,oauth2-0.5.1,omniauth-facebook-1.0.0,omniauth-twitter-0.0.6。 omniauth.rb Rails.application.config.middleware.use OmniAuth::Builder do provider :developer unless Rails.env.production? provider :facebook, ENV[‘167257285348131’], ENV[‘c8c722f697scb2afcf1600286c6212a9′], :scope => ’email,offline_access,read_stream’, :display => ‘popup’ provider :twitter, ENV[‘fma2L22ObJCW52QrL7uew’], ENV[‘4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI’] end session_controller.rb class SessionsController < ApplicationController require 'omniauth-facebook' require 'omniauth-twitter' require 'omniauth' def create @user = User.find_or_create_from_auth_hash(auth_hash) self.current_user = @user redirect_to '/' end def auth_hash request.env['omniauth.auth'] end end 此外,我将’omniauth”omniauth-facebook”omniauth-twitter’gem添加到gemfile中 有两个问题: […]

在RSpec Rails中测试HTTPS(SSL)请求

我想利用rails 3.1rc4中的force_sslfunction 。 class ApplicationController < ActionController::Base force_ssl end 问题是这打破了我现有的RSpec控制器规格的大部分/全部。 例如,这失败了: describe “GET ‘index'” do it “renders the Start page” do get :index response.should render_template ‘index’ end end 而不是呈现页面响应是301重定向到https://test.host/ 。 如何更改我的规范以模拟HTTPS GET / POST? 我是否必须手动更改每个测试或是否有更简单的方法? (我意识到我只能在生产中调用force_ssl ,但这并不理想。实际上,我应该测试force_ssl确实会在预期时重定向到https://。)

Rails response_with在索引和创建方法上的行为不同

我在Rails 3.1中构建一个简单的json API。 我创建了一个具有两个function的控制器: class Api::DogsController “success”}) end def create respond_with({:msg => “success”}) end end 在routes.rb我有 namespace :api do resources :dogs end 当我向http:// localhost:3000 / api / dogs发出get请求时,我从上面得到了正确的json。 当我对同一个url发帖时,我得到一个rails例外: ArgumentError in Api::DogsController#create Nil location provided. Can’t build URI. actionpack (3.1.0) lib/action_dispatch/routing/polymorphic_routes.rb:183:in `build_named_route_call` actionpack (3.1.0) lib/action_dispatch/routing/polymorphic_routes.rb:120:in `polymorphic_url’ actionpack (3.1.0) lib/action_dispatch/routing/url_for.rb:145:in `url_for’ 但是,如果我将创建代码更改为 def create respond_with do […]

如何在Rails 3.1中创建项目期间删除“bundle install”命令?

我正在创建一个新项目: rails new ggg –database=mysql 并得到以下输出: create create README create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/images/rails.png create app/assets/javascripts/application.js create app/assets/stylesheets/application.css create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/mailers create app/models create app/views/layouts/application.html.erb create app/mailers/.gitkeep create app/models/.gitkeep create config create config/routes.rb create config/application.rb create config/environment.rb create config/environments create config/environments/development.rb create config/environments/production.rb create config/environments/test.rb […]