Tag: ruby on rails 3.1

Ruby on Rails:如何使用rails项目添加css文件?

application.html.erb文件: Site 我在public /文件夹中有一个文件“cake.generic.css”。 但是当我重新加载页面时,css文件的效果不起作用。 如果我看到页面查看源代码,我会看到如下内容: Site Home#index Find me in app/views/home/index.html.erb 我该怎么做才能解决这个问题? 如何设置样式表和javascripts的公用文件夹? 看起来app / assets文件夹是为css和js文件设置的?

有一种方法可以同样处理`after_save`和`after_destroy`“吗?

我正在使用Rails 3.1.0,我想知道是否可以“同等”处理after_save和after_destroy回调。 也就是说,我需要为after_save和after_destroy回调运行相同的方法。 此时我必须单独处理这些回调,即使这些回调完成相同的事情: after_save do |record| # Make a thing end after_destroy do |record| # Make the same thing as in the ‘after_save’ callback end 那么, 有一种方法可以“同等”地处理after_save和after_destroy吗?

无法再作为ActiveSupport :: HashWithIndifferentAccess序列化

由于我到目前为止完全无法解密的原因,我不再能够使用ActiveSupport :: HashWithIndifferentAccess了。 模型的相关部分如下所示: class Item < ActiveRecord::Base serialize :metadata, ActiveSupport::HashWithIndifferentAccess (我添加了尝试强制它的选项,但它没有帮助。以前这一切都工作正常,我没有那里。) 只要对象在内存中,一切正常。 这是正确的HashWithIndifferentAccess,生活是美好的。 一旦它被保存到数据库,它就会被保存为Hash: mysql> select * from items; +—-+——+————-+———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————+————-+ | id | link | text | metadata | category_id | +—-+——+————-+———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————+————-+ | 1 | NULL | Apple Store | — id: 42cc7080f964a520e9251fe3 name: Apple Store contact: phone: ‘4153920202’ formattedPhone: (415) 392-0202 location: address: […]

Rails如何汇总列?

示例我有: @test = Pakke.find([[4], [5]]) 在我的Pakke表中,我有一个名为prismd的列 如何将prismd列的两个值相加?

为什么我的RSpec测试失败,但我的应用程序正在运行?

我刚刚完成了Ruby on Rails教程的第10章 ,添加了编辑/更新,索引和销毁用户的function。 一切似乎都在我的应用程序中正常工作,但是当我运行RSpec时,我的许多测试都失败了。 我设置的users_controller_spec与书的设置完全一样,我的应用程序代码也是一样的。 一个问题可能是我使用Rails 3.1.1而不是他在书中使用的Rails 3.0? 它对于以前的测试来说并不是一个问题,只是偶尔会出现几行不同的代码。 在我开始第10.2.1节后 ,问题开始出现。 以下是我看到的错误列表,如果您需要更多信息,请告诉我。 谢谢! 1) UsersController GET ‘index’ for signed-in users should be successful Failure/Error: response.should be_success expected success? to return true, got false # ./spec/controllers/users_controller_spec.rb:31:in `block (4 levels) in ‘ 2) UsersController GET ‘index’ for signed-in users should have the right title Failure/Error: response.should […]

从现有模型/数据库设计安装

我想知道如何为不同用户的现有数据库添加设计。 在这里,我已经有一个客户模型定义,我想改变以允许设计工作。 我已经创建了一个新的迁移并插入了代码 class AddDeviseToCustomer false, :default => ”, :limit => 128 t.confirmable t.recoverable t.rememberable t.trackable t.token_authenticatable t.timestamps end end end 据此,它应该工作。 https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns 。 但是当运行rake db:migrate时,我得到以下内容 undefined method `confirmable’ for # 我运行了以下行 rails g devise:install 任何理由设计都不会认出来,我是否需要做一些事情来说客户是一个设计? 提前致谢

如何从rails 3.1引擎调用父应用程序的帮助方法

我正在构建一个使用“act as”格式的rails引擎来建立与父应用程序的User模型的关系。 module Cornerstone module ActsAsCornerstoneUser extend ActiveSupport::Concern module ClassMethods def acts_as_cornerstone_user(options = {}) #= Associations has_many :cornerstone_discussions #= Options Cornerstone::Config.auth_with << options[:auth_with] if options[:auth_with] Cornerstone::Config.auth_with.flatten! end end module InstanceMethods end end ActiveRecord::Base.send :include, ActsAsCornerstoneUser end 我希望开发人员能够使用:auth_with选项指定帮助器方法名称。 这个想法是开发人员将在父应用程序中指定一个帮助器方法,该方法将返回该会话的登录用户。 我的问题是,一旦开发人员指定了auth_with选项,我该如何调用该父应用程序的方法? 有没有更好的方法来获取父应用程序的登录用户? 我希望它尽可能灵活,以便它不依赖于简单地调用current_user 。

使用windows或linux开始使用Ruby On Rails?

我是Ruby On Rails的新手,我想知道哪个更适合用它。 Windows或Linux。 我之前从未使用过Linux,但我听说最好使用它。 是否有必要像我这样的人安装Linux或我可以使用Windows,结果将与Linux相同?

Heroku:找不到Rakefile(但在本地工作)

我使用Rails 3.1.3克隆了我自己的一个应用程序,在堆栈雪松上的Heroku上创建了一个应用程序,将其推送到Heroku,然后尝试运行 heroku run rake db:migrate并收到此错误消息 No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /usr/local/lib/ruby/1.9.1/rake.rb:2367:in `raw_load_rakefile’ /usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile’ /usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling’ /usr/local/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile’ /usr/local/lib/ruby/1.9.1/rake.rb:1991:in `run’ /usr/local/bin/rake:31:in ` 当我运行rake db:migrate时,我在应用程序的根目录中。 该应用程序适用于localhost。 我有什么想法可能做错了吗? 我注意到的唯一奇怪的是,在错误消息中,它指的是ruby/1.9.1/ 但是,我使用rvm和ruby 1.9.2创建应用程序,当我做ruby -v ruby -v ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] 我的Gemfile source ‘http://rubygems.org’ gem ‘rails’, ‘3.1.3’ # Bundle edge Rails […]

ruby on rails在特定列名后添加一列

我尝试在表中的特定列之后向表中添加一列。 这是我做的: rails generate migration add_reaction_id_to_patient_allergies reaction_id: integer :after => ‘patient_id’ 这是我的迁移文件的样子: class AddReactionIdToPatientAllergies < ActiveRecord::Migration def change add_column :patient_allergies, :reaction_id, :string add_column :patient_allergies, :integer, :string add_column :patient_allergies, :, :after add_column :patient_allergies, :=, :string end end 我不认为命令进展顺利。 我在上面的文件中看到了’=’。 我不认为应该在那里。 有人能告诉我,如果我错过了什么? 如果是这样,我该如何撤消上述内容?