ruby-on-rails-3.1

How can I identify unused i18n keys?

青春壹個敷衍的年華 提交于 2019-12-03 02:56:12
I'm working on an existing Rails app and am using a localization file, en.yml , to hold most of the app's text. At the moment, we aren't localizing into any other languages, so there's just the one file, but the fact that we're putting translate('some.key') into our views means that adding another language will be as simple as adding another file - say, sp.yml The problem is, en.yml has grown to the point that I doubt all the keys are being used. Apart from git grepping for translate calls using each key, is there a quick way to identify localization keys that aren't being explicitly called by

How can I dynamically require assets in the Rails 3.1 asset pipeline?

你。 提交于 2019-12-03 02:46:00
I have a plugin-based system that I use for application development in Rails. Each plugin implements an engine with MVC components, etc. The main application is simply an empty harness that delegates all the work to the plugins that are installed. I'm currently upgrading to Rails 3.1 from Rails 2.3.5, and am trying to get the asset pipeline working with my framework. The problem I'm having is trying to programmatically require my plugin's assets into, for example, the application.js manifest. I can manually add them like so: //= require <plugin_manifest_path> And everything works as expected.

ActiveRecord objects in hashes aren't garbage collected — a bug or a sort of caching feature?

一曲冷凌霜 提交于 2019-12-03 02:44:41
问题 I have a simple ActiveRecord model called Student with 100 records in the table. I do the following in a rails console session: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all ObjectSpace.each_object(ActiveRecord::Base).count # => 100 x = nil GC.start ObjectSpace.each_object(ActiveRecord::Base).count # => 0 # Good! Now I do the following: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all.group_by(&:last_name) ObjectSpace.each_object(ActiveRecord

Override Rails controller routing with capital letters in model name

浪子不回头ぞ 提交于 2019-12-03 02:36:15
I want to create a model in rails: rails generate model ABCThing So this will create a table, abc_things . Great. The problem comes with the controller and routing. I want my controller to be: class ABCThingsController < ApplicationController end However, after adding in the routes.rb resources :abc_things, :only => [:index] and creating the corresponding index view, i get the following error in the browser: Expected /app/controllers/abc_things_controller.rb to define AbcThingsController The problem is easy to see ( "ABCThings".tableize.classify => "AbcThing" ), but i'm not so sure how to fix

Sass mixin for background transparency back to IE8

一世执手 提交于 2019-12-03 02:31:12
问题 I'm new to Sass and struggling with this. I can't get the color to render in both hex (for IE) and rgba . Every little piece is frustrating me because I haven't mastered the syntax yet, and Google results for Sass are still sparse. Here's the mixin: @mixin transparent($hex, $a){ /* for IEGR8 */ background: transparent; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#{$a}#{$hex},endColorstr=#{$a}#{$hex}); zoom: 1; /* for modern browsers */ background-color: rgba(#{$hex},.#{$a

Array Attribute for Ruby Model

别等时光非礼了梦想. 提交于 2019-12-03 02:20:12
问题 Is it possible to create an attribute for a class that is an array? I tried reading this but I didn't get much out of it. I want to do something like this: class CreateArches < ActiveRecord::Migration def change create_table :arches do |t| t.string :name t.array :thearray t.timestamps end end end such that when I call .thearray on an instance of Arch I get an array that I can add new elements to. ruby-1.9.2-p290 :006 > arc = Arch.new ruby-1.9.2-p290 :007 > arc.thearray => [] 回答1: Create a

I need precompile assets every time I've made any change to see difference in browser

萝らか妹 提交于 2019-12-03 01:47:56
Like as I mentioned in title - I have to precompile assets every time I've made any change to see how it looks like - I've tried config.assets.compile = true , without success. I've also tried RAILS_ENV = 'development' but with same effect. Please help me because it is really annoying. My system is running on: Xubuntu Rails -v: 3.1.1 Ruby -v: 1.9.2p290 I also tried: config.action_controller.perform_caching = true One cause of this could be that you ran rake assets:precompile once. The server then uses public/assets exclusively, without trying to compile your assets on the fly. Try removing the

Add defer attribute to javascript_include_tag Rails

我怕爱的太早我们不能终老 提交于 2019-12-03 01:08:34
Is there some way to add the defer attribute easily using the javascript_include_tag helper in Rails? I.e., is there some easy way to turn <%= javascript_include_tag "blah.js" %> into <script defer src="blah.js"></script> <%= javascript_include_tag "blah.js", :defer => "defer" %> This will get you (in development): <script defer="defer" src="/assets/blah.js" type="text/javascript"></script> You can also do <%= javascript_include_tag "blah.js", defer: true %> which is more consistent with other switches. 来源: https://stackoverflow.com/questions/10982375/add-defer-attribute-to-javascript-include

simple_forms custom data attribute

痞子三分冷 提交于 2019-12-03 01:03:43
I would like to have an additional data attribute on an input tag generated by simple_form. The following does not work: <%= f.input :date, :as => 'date_picker', :data => {:datepicker => :datepicker} %> How could this be done? Is it possible at all? As you might have guessed: I am trying to add bootstrap-datepicker to my site without using explicit js to initialize the date picker. rafaelfranca The correct syntax is: f.input :date, :as => 'date_picker', :input_html => { :data => {:datepicker => :datepicker} } For prosperity. On Rails 4.2.5 and Simple Form 3.2.1 The above from @rafaelfranca

Rails counter_cache not updating correctly

青春壹個敷衍的年華 提交于 2019-12-03 00:05:12
Using Rails 3.1.3 and I'm trying to figure out why our counter caches aren't being updated correctly when changing the parent record id via update_attributes. class ExhibitorRegistration < ActiveRecord::Base belongs_to :event, :counter_cache => true end class Event < ActiveRecord::Base has_many :exhibitor_registrations, :dependent => :destroy end describe ExhibitorRegistration do it 'correctly maintains the counter cache on events' do event = Factory(:event) other_event = Factory(:event) registration = Factory(:exhibitor_registration, :event => event) event.reload event.exhibitor_registrations