ruby-on-rails-3

Rails 3 ActiveRecord::Relation random associations behavior

独自空忆成欢 提交于 2020-01-03 05:05:54
问题 I am currently having a strange issue with an application migrated from rails 2.3.8 to rails 3 (3.0.1, 3.0.2, 3.0.3). At random moments associations behave strangely. In some cases, an associated object will return the Relation object, instead of the corresponding model. This seems to happen mostly on polymorphic associations. For example: class A belongs_to :b, :polymorphic => true end class B has_many :a, :as => :source end When invoking "a.b" this will "sometimes" return the Relation

Ruby on Rails: Mass-Assignment on iteration in loop?

爱⌒轻易说出口 提交于 2020-01-03 04:56:06
问题 I'm getting mass-assignment error. Can't mass-assign protected attributes: 1, 2, 3, 4, 5, 6, 7 These numbers represent the iteration in this loop: <% (1..7).each do |i| %> <%= select_tag "hour[#{i}][day]", options_for_select(days_hours) %> <% end %> This is in my model: attr_accessible :day, :open_time, :close_time I'm trying to create an array like this: "hour"=>{ "1"=>{"day"=>"Sunday","open_time"=>"6","close_time"=>"6"}, "2"=>{"day"=>"Sunday","open_time"=>"6","close_time"=>"6"}, "3"=>{"day"

Rails 3 Custom Validator Problem

…衆ロ難τιáo~ 提交于 2020-01-03 04:54:13
问题 I need to apply validation to a Model so that 2 integer values in the record, minimum and maximum, form an inclusive range (ex. 2 and 3 are ok, but 4 and 1 are not). From what I understand, since I need to validate 2 values against each other in the same record, I have to use ActiveModel::Validator (and not ActiveModel::EachValidator). So, I try the following: Model (app/models/position.rb): class Position < ActiveRecord::Base validates_with InclusiveRangeValidator end Validator (app/lib

How to format scientific data into proper data series for graph display in Ruby (Rails 3.1.x)?

时光怂恿深爱的人放手 提交于 2020-01-03 04:42:06
问题 Needing some guidance about how to properly graph data that is very small and stored as BigDecimal. If anyone has had experience using BigDecimals in any graphing scenario I believe your input on how you placed these into a usable sequence would be invaluable. Presently I'm using lazy_high_charts and it really seems that this is going to work out exceptionally well, however I've run into a hitch where I've not dealt with data on the minute BigDecimal scale hitherto. Given my queries, I'll be

Redmine EVM plugin is not working?

喜你入骨 提交于 2020-01-03 04:26:25
问题 Im a redmine user.EVM plugin in redmine is not working when the banner is enabled.Anyone please tell how to resolve this issue ? Started GET "/redmine/admin/plugins" for 10.222.185.22 at 2014-03-10 06:42:05 +0000 Processing by AdminController#plugins as HTML Current user: admin (id=1) Rendered admin/plugins.html.erb within layouts/admin (10.8ms) Rendered admin/_menu.html.erb (12.7ms) Rendered plugins/redmine_banner/app/views/banner/_project_body_bottom.html.erb (0.1ms) Rendered plugins

NameError: uninitialized constant ActionController::Dispatcher

本秂侑毒 提交于 2020-01-03 04:04:08
问题 Found a similar post here but I am running a Mac so the first solution does not exactly apply and the second didn't work for me. Running Mac OS 10.7.2, Xcode 4.2.1, rvm 1.10.1 using ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] I believe the issue to due with rvm, however I do not know how to fix it $ rails new dispatch_me $ rails generate controller demo index $ rails console Loading development environment (Rails 3.2.0.rc2) 1.9.3-p0 :001 > env = {} => {} 1.9.3-p0 :002 > env

How do I customize the length of the token generated in :token_authenticatable in devise - Rails 3?

て烟熏妆下的殇ゞ 提交于 2020-01-03 03:36:09
问题 My token generated seems to be about 20 characters, how do I change the length to something else ? I checked the devise.rb file and tried both: config.token_authentication_key = :access_key config.token_authenticatable.length = 40 produced this error: config/initializers/devise.rb:110:in `block in <top (required)>': undefined method `token_authenticatable' for Devise:Module (NoMethodError) and config.token_authentication_key = :access_key config.token_authentication_key.length = 40 produced

Passing paramters from rails views to jquery (gmap)

眉间皱痕 提交于 2020-01-03 03:33:09
问题 I want to use this jquery plugin in my rails3 apps http://gmap.nurtext.de/ (Google Maps Plugin for jQuery) It seems very easy to use: $("#map").gMap({ markers: [{ latitude: 47.660937, longitude: 9.569803, zoom: 6 }); But i have a question, how i pass the values to this jasvascript code? something like <%= show_map ("47.66","9.56","6") %> or more harcoded $("#map").gMap({ markers: [{ latitude: variable1, longitude: variable2, zoom: variable3 }); 回答1: You need to create a helper function that

bundle install error

依然范特西╮ 提交于 2020-01-03 03:30:09
问题 I'm trying to install this gem: https://github.com/jongilbraith/simple-private-messages with bundle install. And I'm getting the following error message: Updating git://github.com/professionalnerd/simple-private-messages.git Fetching source index for http://rubygems.org/ Could not find gem 'simple-private-messages (>= 0, runtime)' in git://github.com/professionalnerd/simple-private-messages.git (at master). Source does not contain any versions of 'simple-private-messages (>= 0, runtime)'

Link Custom CSS and Javascript to Rails After Deployment

半腔热情 提交于 2020-01-03 03:28:07
问题 I have a Rails App it's css and js links works fine locally since I have used : <link href="assets/bootstrap.css" rel="stylesheet"> <link href="assets/bootstrap-responsive.css" rel="stylesheet"> <link href="assets/font-awesome.css" rel="stylesheet"> <link href="assets/bootswatch.css" rel="stylesheet"> I Googled more than it should all I find is this Heroku Guide , I'm so confused about the assets pipeline thing! I ran this command as well : bundle exec rake assets:precompile and it did create