ruby-on-rails-3.1

Newbie: text replacement in my case

安稳与你 提交于 2019-12-04 06:05:54
问题 In my Ruby on Rails app, I have a method in my helper which opened a file by: content = File.open(myfile.txt) The content of the file is like: my.car , my.seat, my.age; my.son , my.dog, my.chair; ... So, I split the content by " ; " like following: content.split(';').each do |line| #Here, I want to replace the text from "my" to "her" on each line end How to replace each line's "my" to "her" in the content? that's to update content to: her.car , her.seat, her.age; her.son , her.dog, her.chair;

Creating nested models - Rails 3.1

南笙酒味 提交于 2019-12-04 05:31:58
问题 I am trying to create 3 nested models at once, and have trouble with my validations. These are my models: class UserEntity < ActiveRecord::Base has_many :users, :dependent => :restrict, :autosave => true end class User < ActiveRecord::Base has_many :user_login_services, :dependent => :destroy, :autosave => true belongs_to :user_entity end class UserLoginService < ActiveRecord::Base belongs_to :user #validates :user_id, :presence => true end (UserEntity can be a company, with many users.

Is it considered safe to manually edit schema.rb in rails

时光总嘲笑我的痴心妄想 提交于 2019-12-04 05:29:06
I came across a problem where I was working on two branches on a rails project and each project has a migration to add a column. At the time, rake db:migrate:reset cause a problem and I solely relied on my schema.rb to correctly represent the state of my database. At one point, I came across a problem where a column added by branch A got into the schema of branch B. Since migrate:reset was not an option, I resorted to manually editing the schema file to. I committed this change that basically deleted the column from branch A that I did not need in branch B's schema.rb. Problem came after I

Rails, Ruby 1.9.3p0, and mysql gem

*爱你&永不变心* 提交于 2019-12-04 05:26:50
I'm running CentOS6 and installed Ruby from source, along with Rails and some other staff. ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] rails -v Rails 3.1.3 Some gems: *** LOCAL GEMS *** actionmailer (3.1.3, 2.3.14) actionpack (3.1.3, 2.3.14) activemodel (3.1.3) activerecord (3.1.3, 2.3.14) activeresource (3.1.3, 2.3.14) activesupport (3.1.3, 2.3.14) archive-tar-minitar (0.5.2) arel (2.2.1) bigdecimal (1.1.0) bouncy-castle-java (1.5.0146.1) builder (3.0.0) bundler (1.0.21) coderay (0.9.7) columnize (0.3.5) edavis10-object_daddy (0.4.3) erubis (2.7.0) fastercsv (1.5.0) ffi (1

Rails 3.1.0 - undefined method `page_cache_extension' for ActionController::Base:Class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:41:57
When I try load my rails 3.1 app I just get this error. Any ideas? undefined method 'page_cache_extension' for ActionController::Base:Class somewhere I've read that it could be caused because of empty database - do You have one? Check if there You have any records ;) This resolved my problem with it. I removed the following lines from development.rb config.action_view.debug_rjs = true config.action_controller.perform_caching = false Not sure if this is right, but it worked for me. 来源: https://stackoverflow.com/questions/7445917/rails-3-1-0-undefined-method-page-cache-extension-for

ActiveAdmin — How to access instance variables from partials?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 03:41:52
I can't seem to access instance objects in partials. Example: In controller I have: ActiveAdmin.register Store do sidebar "Aliases", :only => :edit do @aliases = Alias.where("store_id = ?", params[:id]) render :partial => "store_aliases" end end Then in the _store_aliases.html.erb partial I have: <% @aliases.each do |alias| %> <li><%= alias.name %></li> <% end %> This doesn't work. The only thing that does work (which is horrible to do as I'm putting logic in a view is this: <% @aliases = Alias.where("store_id = ?", params[:id]) %> <% @aliases.each do |alias| %> <li><%= alias.name %></li> <%

Unable to serialize as ActiveSupport::HashWithIndifferentAccess anymore

谁说我不能喝 提交于 2019-12-04 03:40:12
问题 For reasons that I'm so far completely unable to decipher, I'm no longer able to use ActiveSupport::HashWithIndifferentAccess anymore. The relevant part of model looks like this: class Item < ActiveRecord::Base serialize :metadata, ActiveSupport::HashWithIndifferentAccess (I added the option to try and force it along, but it hasn't helped. Previously this was all working fine, and I didn't have that there.) For as long as the object is in memory, everything works fine. It's correctly a

Rails 3.1 asset pipeline vendor/assets folder organization

☆樱花仙子☆ 提交于 2019-12-04 03:39:48
I'm using the jQuery Tools scrollable library in my Rails 3.1 site with the various assets placed in the vendor/assets folder and it works great. My question is regarding the best way to organize the various files under vendor/assets. What is the recommended way to organize vendor/assets subfolders? Currently I have this structure: vendor/assets/ |-- images/ | |-- scrollable/ | <various button/gradient images> |-- javascripts/ | |-- scrollable/ | jquery.tools.min.js |-- stylesheets/ | |-- scrollable/ | scrollable-buttons.css | scrollable-horizontal.css This is a fairly un-DRY what to do this.

Rails 3.1 link_to not showing confirmation or destroying properly

匆匆过客 提交于 2019-12-04 03:35:07
问题 I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while. In 10.4.2, Michael Hartl uses the following code to delete users: <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %> It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user

javascript - Twitter bootstrap jquery plugins not compiled for production

試著忘記壹切 提交于 2019-12-04 03:21:59
I'm developing a 3.1 Rails app with Twitter Bootstrap using seyhunak's gem . On the production mode, I was able to use basic bootstrap CSS and JS through pipeline precompilation: RAILS_ENV=production bundle exec rake assets:precompile Using the gem file : group :assets do gem 'sass-rails', '~> 3.1.5' gem 'coffee-rails', '~> 3.1.1' gem 'uglifier', '>= 1.0.3' gem "twitter-bootstrap-rails" end And the application.js file: //= require_tree . //= require jquery //= require jquery_ujs //= require twitter/bootstrap //= require bootstrap-tab //= require bootstrap-modal //= require bootstrap-dropdown /