我是Rails的新手,我正在为我的雇主构建一个简单的项目跟踪应用程序.我一直在我的Mac上开发应用程序并将其推送到github.我只是设法将我的github repo克隆到我公司防火墙后面的一个Windows框中,希望让同事们试用这个应用程序.
但是当我去rake db:migrate来初始化windows框中的数据库时,我收到以下错误消息:
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Could not find table 'projects'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/faker-0.3.1/lib/extensions/object.
rb:3:in `returning'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite_adapter.rb:228:in `columns'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1271:in `columns'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1279:in `columns_hash'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1578:in `find_one'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1569:in `find_from_ids'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:616:in `find'
c:/Rails_Projects/molex_app/config/routes.rb:15
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:226:in `draw'
c:/Rails_Projects/molex_app/config/routes.rb:1
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load_without_new_constant_marking'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:521:in `new_constants_in'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `load_routes!'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `each'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `load_routes!'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现 Ryan Bates 的可排序表列代码(Railscast #228),但我希望能够对关联列进行排序。特别是,我有以下模型和关联:
class Project < ActiveRecord::Base
belongs_to :program_manager, :class_name => "User"
class User < ActiveRecord::Base
has_many :program_manager_projects, :class_name => "Project", :foreign_key => "program_manager_id"
Run Code Online (Sandbox Code Playgroud)
项目模型和用户模型之间的关联由“program_manager_id”外键调节,用户使用集合选择下拉列表在新/编辑视图中设置该外键。这是project.rb顶部注释的一部分:
# Table name: projects
# program_manager_id :integer
Run Code Online (Sandbox Code Playgroud)
我希望能够按项目经理的姓名(即project.program_manager.name)对索引视图中的项目列表进行排序。
理想情况下,我能够以某种方式将 :order 指向这个名称,也许在我的 ProjectsController 的索引方法中使用类似的东西:
@projects = Project.find(:all, :order => project.program_manager.name)
Run Code Online (Sandbox Code Playgroud)
但这显然行不通(更不用说 Ryan 的例程通过对要排序的模型中的表名称的特定引用来实现这一点。)
我遇到过一些使用named_scope的令人生畏的方法,例如:
named_scope :most_active, :select => "questions.*", :joins => "left join comments as comments_for_count on comments_for_count.question.id = questions.id", :group => "questions.id", :order => "count(questions.id) desc"
Run Code Online (Sandbox Code Playgroud)
但由于我缺乏 MySQL 专业知识,这对我来说相当难以理解。
任何人都可以帮助我针对我的具体情况概括上面的named_scope示例,或者为我指出一个更直接的策略吗?
非常感谢,
院长