ruby-on-rails-3.1

How to pluralize “There is/are N object/objects”?

流过昼夜 提交于 2019-11-29 11:08:52
问题 Pluralizing a single word is simple: pluralize(@total_users, "user") But what if I want to print "There is/are N user/users": There are 0 users There is 1 user There are 2 users , i.e., how to pluralize a sentence ? 回答1: You can add a custom inflection for it. By default, Rails will add an inflections.rb to config/initializers . There you can add: ActiveSupport::Inflector.inflections do |inflect| inflect.irregular "is", "are" end You will then be able to use pluralize(@total_users, "is") to

undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x9dee690>

时光总嘲笑我的痴心妄想 提交于 2019-11-29 10:55:19
问题 I am using Active Admin gem for my small application based on Quiz. But when I execute rake db:migrate it gives me error. Following is the trace of the command : $ rake db:migrate RAILS_ENV=production --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:migrate == DeviseCreateAdminUsers: migrating ===================

find(:first) and find(:all) are deprecated

社会主义新天地 提交于 2019-11-29 10:35:06
I am using RubyMine with rails 3.2.12 and I am getting following deprecated warning in my IDE. Any Idea How can I solve this deprecated warning? find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2. I changed my answer after @keithepley comment #Post.find(:all, :conditions => { :approved => true }) Post.where(:approved => true).all #Post.find(:first, :conditions => { :approved => true }) Post.where(:approved => true).first or post = Post.first or post = Post.first! or post = Post.last or post = Post.last! You can read more from

How to add confirm message with link_to Ruby on rails

我的未来我决定 提交于 2019-11-29 10:31:44
问题 I wanted to add confirmation message on link_to function with Ruby. = link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?' Any ideas why it's not working? 回答1: First, you should verify that your layout have jquery_ujs . Best practice to do it by including it in your main application.js : //= require jquery_ujs Check that you included application.js in your layout: = javascript_include_tag :application While, in development mode, view your source html and verify jquery_ujs.js

How do I display the user's location with a marker in gmaps4rails?

て烟熏妆下的殇ゞ 提交于 2019-11-29 10:27:19
问题 I have been trying to get a custom use of gmaps4rails running, and I have the code set to display my string of json coordinates on the map, and the center on user IS working, I can zoom into my location from home, work and my phone. I just cannot get the js right to display an 'Im here' button on the map once permission is given. here is the code I use for the map from gmaps4rails: <%= gmaps(:map_options => {:detect_location => true, :center_on_user => true, :auto_zoom => false, :zoom => 12,

Asset pipeline, compass font-face and eot?iefix call to the font

非 Y 不嫁゛ 提交于 2019-11-29 09:59:30
问题 I am trying to use a Compass font-face mixin, which contains the inclusion of *.eot?iefix My app/assets/fonts contains all the font types needed, including .eot. When I try to run assets:precompile the task fails saying something like: webfont.eot?iefix isn't precompiled Do you know the possible solution for this problem? It runs with no error in case I have config.assets.compile = true, but as I've understood it's better not to use it on production. 回答1: You can do it with pure Scss too:

Warning. Error encountered while saving cache … can't dump anonymous class

百般思念 提交于 2019-11-29 09:28:42
When app is deployed with capistrano errors occur in production.log. Compiled signup.css (30ms) (pid 31797) Warning. Error encountered while saving cache /home/deployer/apps/example.com/releases/20140315211501/tmp/cache/sass/c76a96d592cb37dc7092a4e2f10ad8d3d22bcc8b/user_sessions.css.scssc: can't dump anonymous class #<Class:0x0000000356d120> Compiled user_sessions/user_sessions.css (16ms) (pid 31797) Compiled user_sessions.css (20ms) (pid 31797) Warning. Error encountered while saving cache /home/deployer/apps/example.com/releases/20140315211501/tmp/cache/sass

asset_path in scss file rails

我的梦境 提交于 2019-11-29 09:15:25
I am having issues with asset_path in production. Rails 3.1.1 #config/environments/development.rb Scc::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable

Assets not being run though the .erb preprocessor

纵饮孤独 提交于 2019-11-29 08:21:54
I am having trouble trying to rake assets:precompile in my rails 3.1 app. I keep getting the following error: rake aborted! Invalid CSS after "...und-image: url(": expected ")", was "<%= asset_path(..." It seems that the erb preprocessor is not being invokeb but my file is called style.css.scss.erb . Any suggestions? Ruby documentation seems a bit unclear on a few things such as the usage of the asset_path and other such helper in stylesheets. Anyways this is what I did to get around the exact same problem: I decided to do this the SASS-way by changing my stylesheet extensions from css to scss

Rails 3.1 newbie : where should I put javascript code?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 06:45:40
I am developing Rails 3.1 application, I get confused about where should I put my own javascript code(e.g. my.js ) and where to put 3rd-party javascript library (e.g. jQuery-UI ). I know in the old version Rails, javascript should all goes into public/javascripts/ directory, when I generate Rails 3.1 app, there is no public/javascripts/ folder, but there is app/assets/ and verndor/assets/ and there is application.js in app/assets , I would like to ask: in Rails 3.1 ,where should I put my.js and jQuery-UI js in Rails 3.1?? what is the app/assets/application.js supposed to do? how can I include