ruby-on-rails-3

WARNING: Can't mass-assign protected attributes

浪子不回头ぞ 提交于 2019-12-31 22:42:20
问题 I get this error "WARNING: Can't mass-assign protected attributes: races_attributes" , when following this http://railscasts.com/episodes/196-nested-model-form-part-1 on rails 3. Where Races are a component of Events. This is my models/race.rb: class Race < ActiveRecord::Base belongs_to :event attr_accessible :name, :unit end This is my models/event.rb: class Event < ActiveRecord::Base has_many :races, :dependent => :destroy accepts_nested_attributes_for :races attr_accessible :name, :date,

Getting First Name/Last Name/Email from Twitter using OAuth

天涯浪子 提交于 2019-12-31 22:42:12
问题 I'm using omniauth exclusively to allow login to my website with facebook/google/twitter. I store first name, last name, and email. However, when I raise the twitter auth hash from oauth I only get nickname, name, location, image, description and urls in the auth hash. Is there a scope I can pass in my initializer to get the user's email and break name out into the first_name, last_name fields? 回答1: Twitter does not give out user emails so you will not be able to get that information from the

How to Create Download Link

为君一笑 提交于 2019-12-31 22:37:13
问题 What's the best way to create a download link? Is there a better way than the following? I was thinking of using link_to "Download", :controller => ..., :action => ...", :id => ... in the view. Adding match /documents/download/:id => documents#download to routes.rb And in the controller: def download send_file ... end Also, I'd like, if possible, for the user to remain on the same page as the link. Thanks. 回答1: I add the download action as a restful route in a resources block. Here's typical

Delayed Job not logging in Production

▼魔方 西西 提交于 2019-12-31 22:36:32
问题 I want my delayed job "code" to log in a different log file for business requirements. So I log a custom status in a log called as dj.log. Inside the "serialized" job, I am putting the log statements to log in my file. Here is how the setup is Delayed::Worker.destroy_failed_jobs = false Delayed::Worker.sleep_delay = 60 Delayed::Worker.max_attempts = 10 Delayed::Worker.delay_jobs = !( Rails.env.test? || Rails.env.development? ) #dont use delayed_job in development or test mode #Delayed_job

rspec returns “PG::Error: ERROR: relation ”table_name“ does not exist”

血红的双手。 提交于 2019-12-31 21:42:34
问题 Environment is REE(2011.12) on rvm, rspec 2.8.0, rails 3.0.6, and pg 0.13.2. Using PostgreSQL 8.3.17 on CentOS 5.6. The db:migrate have work correctly. But rspec have got following error. 1) ApiController articles OK Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "table_name" does not exist : DELETE FROM "table_name" I'm updating my project from rails 2.3.5 with rspec 1.x series to rails 3.0 with rspec2. Copied all rspec

respond to only json in rails

天涯浪子 提交于 2019-12-31 20:16:29
问题 In my rails app which is json only, I want to send a 406 code whenever someone calls my rails app with accept header set to anything except application/json. I also want it to send a 415 when I get the content type set to anything except application / json My controllers have respond_to :json put on them. I only render json in all actions. However how do I ensure that I return error code 406/415 for all calls for anything that is called for all other accept headers/content-type and with

Is there a fix for the “Could not find *gem* in any of the sources” error that doesn't involve deleting Gemfile.lock?

痞子三分冷 提交于 2019-12-31 17:57:24
问题 I am trying to get my development environment setup on a new computer. git clone -o heroku git@heroku.com:theirapp.git cd theirapp bundle Fetching gem metadata from https://rubygems.org/...... Fetching gem metadata from https://rubygems.org/.. Could not find jquery-rails-2.0.0 in any of the sources After googling this error, the response seems to be to delete Gemfile.lock , then running bundle again. This works, but then I have different versions of gems where I haven't specified a version in

Is there a fix for the “Could not find *gem* in any of the sources” error that doesn't involve deleting Gemfile.lock?

让人想犯罪 __ 提交于 2019-12-31 17:56:55
问题 I am trying to get my development environment setup on a new computer. git clone -o heroku git@heroku.com:theirapp.git cd theirapp bundle Fetching gem metadata from https://rubygems.org/...... Fetching gem metadata from https://rubygems.org/.. Could not find jquery-rails-2.0.0 in any of the sources After googling this error, the response seems to be to delete Gemfile.lock , then running bundle again. This works, but then I have different versions of gems where I haven't specified a version in

Rails where date is greater than given date query

断了今生、忘了曾经 提交于 2019-12-31 17:40:29
问题 Trying to search where movies coming out have a release date greater than today's date Movie.where('release > ?', Date.today) ActiveRecord::StatementInvalid: Mysql::ParseError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release > '2011-09-25')' at line 1: SELECT `movies`.* FROM `movies` WHERE (release > '2011-09-25') 回答1: Rails 3+ : Movie.where('release > ?', DateTime.now) Pre Rails 3 Movie.where([

memorable name generator gem for ruby

流过昼夜 提交于 2019-12-31 17:37:55
问题 Before I go roll my own and start pulling out the dictionary, does anyone know a rubygem to generate memorable names suitable for app keys. I need something pronounceable so that I can give users unique email addresses to submit content to. I like Heroku's naming for it's apps as an example. floating-sky-58 simple-fog-45 回答1: You can use randexp gem. It's use the dictionnary from your OS ( UNIX only ) with randexp gem you can do something like : /[:word:]-[:word:]-\d+/.gen and have like