ruby-on-rails-3.1

How to use multiple databases for one rails 3.1 app in Heroku?

99封情书 提交于 2019-11-27 14:50:16
问题 My Rails 3.1 application connects to 2 databases, one is the default, the other is an Amazon RDS MYSQL instance. The current database.yml contains two production database connections. The models that need to pull from the second database simply use establish_connection "production_on_amazon" Unfortunately Heroku overwrites your database.yml, and only seems to inlcude one database connection. Does anyone know how I can add or configure my second? Running "heroku config" I can see there are 2

Listing 'rake routes' for a mountable Rails 3.1 engine

百般思念 提交于 2019-11-27 14:34:44
问题 I'm working on a mountable engine for use with Rails 3.1, and I want to list the engine's routes. I created the engine using: $ rails plugin new rails_blog_engine --mountable And edited the 'test/dummy/config/routes' file to read: Rails.application.routes.draw do mount RailsBlogEngine::Engine => "/blog" end ...and 'config/routes' to read: RailsBlogEngine::Engine.routes.draw do resources :posts end I want to list the routes generated for ':posts', but it's not clear how I can do this. When I

rake assets:precompile is slow

℡╲_俬逩灬. 提交于 2019-11-27 14:28:26
问题 The command "rake assets:precompile" works very slow for me. Especially on my Amazon EC2 Micro production server which does not have a lot of processor resources. On EC2 I have to wait 1 minute or more during each deployment just for this precompile task alone. Is there a way to make it faster? Previously I used Jammit to compress/minify css and js. Jammit worked nearly 10 times faster on the same web site and servers. 回答1: If you don't need to load the Rails environment, you should disable

Rails 3.1 remote requests submitting twice

﹥>﹥吖頭↗ 提交于 2019-11-27 12:54:17
I developed a Rails 3.1 application that consists of a 100% Ajax CRUD forms to input users and customers. I created two separate models, controllers, views etc. The views for each model contain jquery files for create edit update and destroy. The problem is when I perform any operation that performs a remote operation, it is called twice. I can confirm this happening in console view in firebug as well as output in WEBrick output. Can anyone assist in tracking down what happened here? What would cause rails to process each call twice? If you have precompiled the assets and running in

rails mysql adapter error

六月ゝ 毕业季﹏ 提交于 2019-11-27 12:35:44
问题 I'm having trouble finding a solution to this problem. I'm getting the error Please install the mysql adapter: 'gem install activerecord-mysql-adapter' when I specify either ruby-mysql or mysql2 in my Gemfile . This has only happened since I've upgraded to Rails 3.1.0-rc1. I'm running OSX 10.6, Ruby 1.9.2. cody$ rails c /Users/cody/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish

Rails 3.1 limit user created objects

血红的双手。 提交于 2019-11-27 11:44:11
I would like to limit the number of model Objects a user can create. I've tried the below but it is not working. I understand some changes have happened in rails 3.1 and not sure how to accomplish this now. class User < ActiveRecord::Base has_many :things, :limit => 5, :dependent => :destroy # This doesn't work end class Things <ActiveRecord::Base belongs_to :user end Try something like this: class User < ActiveRecord::Base has_many :things end class Things <ActiveRecord::Base belongs_to :user validate :thing_count_within_limit, :on => :create def thing_count_within_limit if self.user.things(

Changing a column type to longer strings in rails

我的梦境 提交于 2019-11-27 11:31:13
At the first migration, I declared on a column content to be string Activerecord made it to be string(255) according to annotate gem. After I push the app to heroku, which uses postgres, if I enter in the form in content a string longer than 255 I get the error PGError: ERROR: value too long for type character varying(255) Problem is I need that content to contain a string that is extremely long perhaps (free text, could be thousands of chars) What variable (is string is not appropriate for this) would pg accept? How do I create a migration to replace the type of that column thanks You should

How do I write a Rails 3.1 engine controller test in rspec?

我的梦境 提交于 2019-11-27 11:19:01
I have written a Rails 3.1 engine with the namespace Posts. Hence, my controllers are found in app/controllers/posts/, my models in app/models/posts, etc. I can test the models just fine. The spec for one model looks like... module Posts describe Post do describe 'Associations' do it ... end ... and everything works fine. However, the specs for the controllers do not work. The Rails engine is mounted at /posts, yet the controller is Posts::PostController. Thus, the tests look for the controller route to be posts/posts. describe "GET index" do it "assigns all posts as @posts" do Posts::Post

Using @font-face with Rails 3.1 app?

☆樱花仙子☆ 提交于 2019-11-27 10:48:28
I'm having trouble using the following @font-face declaration to work with my Rails 3.1 app. I put the fonts in the Asset Pipeline in its own folder called "Fonts" alongside images and stylesheets and javascripts Here is the declaration I used (generated by Font Squirrel.) @font-face { font-family: 'ChunkFiveRegular'; src: url('Chunkfive-webfont.eot'); src: url('Chunkfive-webfont.eot?#iefix') format('embedded-opentype'), url('Chunkfive-webfont.woff') format('woff'), url('Chunkfive-webfont.ttf') format('truetype'), url('Chunkfive-webfont.svg#ChunkFiveRegular') format('svg'); font-weight: normal

What does require_self mean?

强颜欢笑 提交于 2019-11-27 10:40:28
问题 In rails3.1 application.css we could see /* *= require_self *= require_tree . */ I know that require_tree . is just telling the system to bundle together everything from the stylesheets folder into a single file. But what does require_self tells? 回答1: From http://guides.rubyonrails.org/asset_pipeline.html: /* ... *= require_self *= require_tree . */ "In this example require_self is used. This will put the CSS contained within the file (if any) at the top of any other CSS in this file unless