Rails

How to Highlight Fields on Rails Validation Errors

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you display form field highlighting for fields that fail validation errors in Rails 3.1? I know that scaffolding automatically generates the css and controller code to handle this, but I was wondering if there was a way to generate that manually. I have already implemented the string display of error messages through: @user.errors.full_messages.each...etc, but I can't get the fields to become highlighted in red. Any ideas? Thanks. 回答1: Assuming you have an error class for fields in your CSS file: "error" %> Is this what you want?

Error installing mysql2: Failed to build gem native extension

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysql2 it gives me the following error: Error installing mysql2: ERROR: Failed to build gem native extension. How can I fix this and successfully install mysql2 ? 回答1: On Ubuntu/Debian and other distributions using aptitude: sudo apt-get install libmysql-ruby libmysqlclient-dev Package libmysql-ruby has been phased out and replaced by ruby-mysql . This is where I found the solution. If the above command

How to configure CKEditor in Rails 3.1 (gem + Asset Pipeline)

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've successfully configured the ckeditor gem from https://github.com/galetahub/ckeditor on my Rails 3.1 app. My problem now is that I can't figure out how to configure the CKEditor. The files that are used according to the Readme simply don't exists in a Rails 3.1 application with the asset pipeline enabled. 回答1: The answer was easy once i've figured out the thrown error message. /app/assets/javascript/ckeditor CKEDITOR . editorConfig = function ( config ) { config . toolbar_MyToolbar = [ { name : 'document' , items : [ 'NewPage'

sass-rails asset pipeline: generating image paths incorrectly; `url(/images/blah.png)` instead of `url(/assets/blah.png)`

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In section 2.2.2, "CSS and Sass" , I'm told to put image-url('delete.png') in my sass. And so I have. However, it is generating CSS like background-image: url(/images/delete.png) instead of the thing that I'm told everywhere it should be generating, the correct and obvious thing, background-image: url(/assets/delete.png) What. The heck. I have spent literal days trying to figure out where this is coming from. Here's a gist of relevant settings that are resulting in this behavior. Here's a gist of the same files in an earlier version of our

Rails switch case in the view

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to write a switch case in my view : "one") %> "two") %> "three") %> But it doesn't work. Do I have to add a somewhere in each line ? Any ideas ? Thanks ! 回答1: You should pull your first when into same block as case "one") %> "two") %> "three") %> 回答2: Don't put to much logic in your views. i would add a helper def humanize_number(number) humanized_numbers = {"0" => "zero", "1" => "one"} humanized_numbers[number.to_s] end than you can call it from the view with humanized_number(index)) %> 回答3: First, you should really think about

Rails 3.2 undefined method `key?' for nil:NilClass

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: For some reason I started to get this error after switching to Rails 3.2. I guess it has something to do with acl9 plugin, which I tried reinstalling, but nothing changed. I moved the plugins to lib/plugins and added initializer to config/initializers but again, same error. I looked for solution at acl9 repo on Github, but could not find anything there. Maybe it is not acl9 after all. I have paperclip, acl9, authlogic installed. NoMethodError ( undefined method `key?' for nil:NilClass): actionpack (3.2.1) lib/action_controller

Ruby on Rails, delayed_job

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using this gem for my application. I cannot find parameters that I need.I have two functions in my controller: create and analyse. I want to run an analyse-method after 5 min when a create-method was called or I have one more function in a model: process I want to run an anylse-method (from contoller) after 5 min when a process-method was called. I have found smt like this: handle_asynchronously : in_the_future , : run_at => Proc . new { 5.minutes . from_now } but it does not say after wich function it should be called. edit:

Rails has_many through migration

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: im doing a many to many association with my models i belive after i did this: class Competence < ActiveRecord::Base has_many :behaviour, through: :behaviours_rel has_many :stabilizer, through: :stabilizers_rel end class Behaviour < ActiveRecord::Base belongs_to :competence end class Stabilizer < ActiveRecord::Base belongs_to :competence end i have to do a migration something like rails generate migration behaviour:belongs_to but it doesnt work i dont get the logic of doing this migration with rails generate im trying to save in a competence

rails postgresql connection could not connect to server: Connection refused

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I print root@a:/home/rails/car_main# RAILS_ENV=production rake db:create And get this: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new' /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord

Rails FasterCSV “unquoted fields do not allow \\r or \\n”

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm having an issue with FasterCSV and my rake db:seeds migration. I get the error: "rake aborted! Unquoted fields do not allow \r or \n (line 2)" on the following seeds.rb data: require 'csv' directory = "db/init_data/" file_name = "gardenzing020812.csv" path_to_file = directory + file_name puts 'Loading Plant records' # Pre-load all Plant records n = 0 CSV . foreach ( path_to_file ) do | row | Plant . create ! : name => row [ 1 ], : plant_type => row [ 3 ], : group => row [ 2 ], : image_path => row [ 45 ], : height => row [ 5 ],