ruby-on-rails-3

Using raw sql queries in Rails 3 application?

浪子不回头ぞ 提交于 2020-01-12 16:10:04
问题 I am working on migrating a legacy database into my Rails application (3.2.3). The original database comes with quite a few long sql queries for reports. For now, what I would like to do it use the sql queries in the Rails application and then one by one (when time allows) swap the sql queries to 'proper' Rails queries. I have a clinical model and the controller has the following code: @clinical_income_by_year = Clinical.find_all_by_sql(SELECT date_format(c.transactiondate,'%Y') as Year, date

Why is :notice not showing after redirect in Rails 3

…衆ロ難τιáo~ 提交于 2020-01-12 14:29:33
问题 I have the following code in my controller def create @tv_show = TvShow.new(params[:tv_show]) respond_to do |format| if @tv_show.save format.html { redirect_to(tv_shows_path, :notice => 'Tv show was successfully created.') } format.xml { render :xml => @tv_show, :status => :created, :location => @tv_show } else format.html { render :action => "new" } format.xml { render :xml => @tv_show.errors, :status => :unprocessable_entity } end end end and the following in my tv_shows/index.html.erb <div

How to specify the path of the public directory in a ruby on rails app?

不羁岁月 提交于 2020-01-12 14:26:48
问题 I want to parse .csv file which is in public folder, I've tried /../ 's, #{RAILS_ROOT}/public but with no success (No such file or directory error). I dunno exactly how to use Rails.public_path ( Rails.public_path/filename.csv doesn't work) please help 回答1: You have access to the Rails.root path, use it to get a path Rails.root.join("public", "filename.csv") You'll possibly have to call to_s on it depending on how you want to use the result (as a Path object or as a string). 回答2: In Rails 4,

Error reporting when sending emails with delayed_job

流过昼夜 提交于 2020-01-12 14:26:23
问题 What's the proper way to get error reports, when using a tool like AirBrake or ExceptionNotifier from mailing delayed jobs? I tried to creating my own delayed job class, but the mail object created by Mailer.welcome() (or similar) is not serialized correctly. I also tried adding an error(job, exception) method to the PerformableMailer and PerformableMethod classes, but I got more errors generally related to serializing I believe. I tried both psych and sych for the serialization. 回答1: Updated

How to specify the path of the public directory in a ruby on rails app?

爱⌒轻易说出口 提交于 2020-01-12 14:24:50
问题 I want to parse .csv file which is in public folder, I've tried /../ 's, #{RAILS_ROOT}/public but with no success (No such file or directory error). I dunno exactly how to use Rails.public_path ( Rails.public_path/filename.csv doesn't work) please help 回答1: You have access to the Rails.root path, use it to get a path Rails.root.join("public", "filename.csv") You'll possibly have to call to_s on it depending on how you want to use the result (as a Path object or as a string). 回答2: In Rails 4,

list Rails controller instance variables

此生再无相见时 提交于 2020-01-12 14:17:29
问题 i was trying to list the instance variables inside a controller but came up with irb>HomeController.instance_variable_names => ["@visible_actions", "@inheritable_attributes", "@controller_path", "@action_methods", "@_process_action_callbacks"] and I tried it on the action irb>HomeController.action("index").instance_variable_names => [] so what do controller Instance variables belong to? 回答1: The instance variables belong to the instantiated controller object, and are only created when the

list Rails controller instance variables

守給你的承諾、 提交于 2020-01-12 14:16:48
问题 i was trying to list the instance variables inside a controller but came up with irb>HomeController.instance_variable_names => ["@visible_actions", "@inheritable_attributes", "@controller_path", "@action_methods", "@_process_action_callbacks"] and I tried it on the action irb>HomeController.action("index").instance_variable_names => [] so what do controller Instance variables belong to? 回答1: The instance variables belong to the instantiated controller object, and are only created when the

Ruby on rails - Error during bundle install

不羁岁月 提交于 2020-01-12 13:48:13
问题 I've been googling this error below, but I can't solve this error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /usr/bin/ruby2.1 extconf.rb mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h extconf failed, exit code 1 Gem files will remain installed in /home/dyego/.bundler/tmp/9200/gems/sqlite3-1.3.9 for inspection. Results logged to /home/dyego/.bundler/tmp/9200/extensions/x86_64-linux/2.1.0/sqlite3-1.3.9/gem_make.out An error occurred while

Ruby on rails - Error during bundle install

人盡茶涼 提交于 2020-01-12 13:47:51
问题 I've been googling this error below, but I can't solve this error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /usr/bin/ruby2.1 extconf.rb mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h extconf failed, exit code 1 Gem files will remain installed in /home/dyego/.bundler/tmp/9200/gems/sqlite3-1.3.9 for inspection. Results logged to /home/dyego/.bundler/tmp/9200/extensions/x86_64-linux/2.1.0/sqlite3-1.3.9/gem_make.out An error occurred while

Ruby on rails - Error during bundle install

回眸只為那壹抹淺笑 提交于 2020-01-12 13:47:29
问题 I've been googling this error below, but I can't solve this error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /usr/bin/ruby2.1 extconf.rb mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h extconf failed, exit code 1 Gem files will remain installed in /home/dyego/.bundler/tmp/9200/gems/sqlite3-1.3.9 for inspection. Results logged to /home/dyego/.bundler/tmp/9200/extensions/x86_64-linux/2.1.0/sqlite3-1.3.9/gem_make.out An error occurred while