ruby-on-rails-2

How to monkey-patch code that gets auto-loaded in Rails?

余生颓废 提交于 2019-11-28 21:26:20
I'm monkey-patching a Rails engine with something like: SomeClass.class_eval do # ... end The first time I hit the web site, on development mode at least, it works, but the second time it's like my patch never existed. I presume it's Rails auto-reloading the engine (which is installed in vendor/) and not reloading my code. This is Rails 2.3. Any ideas how to do it so that my code also gets reloaded? EDIT: This solution only works for Rails 3+ since it's dependent on some functionality in Rails::Railtie. Put this code in an initializer. This question is quite old, but here's a solution I found:

Rails Flash.now not working

只愿长相守 提交于 2019-11-28 19:04:17
问题 I have a view from which I make an ajax request to the controller and after the action is successfully completed I initialize the flash.now[:notice] . But after the control goes back to the view. I don't happen to see the flash message. flash.now[:notice] = "Request Completed successfully" if @meetings.any? 回答1: When redirecting use flash[:notice] = "This message value is available in next request-response cycle" When rendering use flash.now[:notice] = "Message is available in same request

mysql2.so: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

↘锁芯ラ 提交于 2019-11-28 07:23:07
I am trying to run a Rails two app with Ubuntu 10.04 server, sphinx, myql2 version 0.2.7 and percona server 5.5 (Myslql 5.5). mysql2 in irb works ok, I can connect to the db. this rails 2 app is working in another Centos server with MySql 5.1. When I run: script/server -e production I get: mysql2.so: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory here are the libs I have: # ls -l /usr/lib |grep sql -rw-r--r-- 1 root root 10581008 2011-11-18 16:51 libmysqlclient.a lrwxrwxrwx 1 root root 16 2011-12-10 05:48 libmysqlclient_r.a -> libmysqlclient.a lrwxrwxrwx 1

Polymorphic Assocations using Integer ID type fields

若如初见. 提交于 2019-11-28 03:15:26
问题 I have a table Foo that has a polymorphic belongs_to association called bar . The foos table has the standard bar_id column. However, instead of a string-based bar_type column, I have an integer bar_type_id column. This column references the id column in the table bar_types . bar_types.name holds the name of the class that represents the class of the particular bar instance. Does Rails (ideally >=2.3.10) allow for this type of polymorphic association? 回答1: We did it by overriding the

Failing to access environment variables within `database.yml` file

狂风中的少年 提交于 2019-11-27 17:22:58
I have the following developement section of my development.yml file: development: adapter: postgresql host: localhost database: testtb username: app_user password: ENV['APP_USER_POSTGRES_PASSWORD'] <= Troublesome line When I open a rails console via bundle exec rails console and type ENV['APP_USER_POSTGRES_PASSWORD'] I get back the DB password I've specified in my local profile. However, when I start my rails server, it can't connect to the DB, failing with PGError FATAL: password authentication failed for user "app_user" This was previously working when I had the DB password actually typed

undefined method `source_index' for Gem:Module (NoMethodError)

蹲街弑〆低调 提交于 2019-11-27 16:46:55
I'm running a Rails 2.3.5 application and upon running script/server I am shown the following: ./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError) from ./script/../config/boot.rb:60:in `load_initializer' from ./script/../config/boot.rb:44:in `run' from ./script/../config/boot.rb:17:in `boot!' from ./script/../config/boot.rb:123 from script/server:2:in `require' from script/server:2 If I comment out line 60 in boot.rb (Rails::GemDependency.add_frozen_gem_path) and run script/server, I

How to monkey-patch code that gets auto-loaded in Rails?

流过昼夜 提交于 2019-11-27 14:00:50
问题 I'm monkey-patching a Rails engine with something like: SomeClass.class_eval do # ... end The first time I hit the web site, on development mode at least, it works, but the second time it's like my patch never existed. I presume it's Rails auto-reloading the engine (which is installed in vendor/) and not reloading my code. This is Rails 2.3. Any ideas how to do it so that my code also gets reloaded? 回答1: EDIT: This solution only works for Rails 3+ since it's dependent on some functionality in

Force SSL using ssl_requirement in Rails 2 app

丶灬走出姿态 提交于 2019-11-27 13:12:07
I have a Rails application which need to run under SSL. I tried ssl_requirement but seems I have to type in all the actions in every controllers. Is there any method that I can add a before_filter in application controller with ssl_requirement, so that the apps will redirect to https automatically when user request is in http? Thanks all. :) Use a Rack Middleware . # lib/force_ssl.rb class ForceSSL def initialize(app) @app = app end def call(env) if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https' @app.call(env) else req = Rack::Request.new(env) [301, { "Location" => req.url

Upgrading from Rails 2.3.8 to 4.0

醉酒当歌 提交于 2019-11-27 11:15:31
I am running an application on Rails 2.3.8. I am planning to upgrade it to Rails 4.0 (which is in RC). What will be the easiest way for me to do this? Do I need to first upgrade to Rails 3.x? Note: in my current implementation, I am using starling and ferret; as part of upgrade I am also considering to move to sidekiq and sunspot This is a multi-step process, and depending on the size of your application, it can take a long time. At each step, you'll want to test your application for bugs and problems and broken gems (because they are most certainly going to crop up). I have included links for

ActiveRecord::Base Without Table

不羁的心 提交于 2019-11-27 06:45:49
This came up a bit ago ( rails model attributes without corresponding column in db ) but it looks like the Rails plugin mentioned is not maintained ( http://agilewebdevelopment.com/plugins/activerecord_base_without_table ). Is there no way to do this with ActiveRecord as is? If not, is there any way to get ActiveRecord validation rules without using ActiveRecord? ActiveRecord wants the table to exist, of course. This is an approach I have used in the past: In app/models/tableless.rb class Tableless < ActiveRecord::Base def self.columns @columns ||= []; end def self.column(name, sql_type = nil,