1

在http://refinerycms.com/guides/getting-started#rails-application-templates上学习使用 Refinery CMS 的教程

6 使用您的第一个引擎扩展炼油厂

说要运行

rails generate refinery:engine singular_model_name attribute:type [attribute:type ...]

然后运行

rails generate refinery:engine event title:string date:datetime photo:image blurb:text

之后我完成了其余的工作,但rake db:migrate似乎没有工作,因为当我尝试运行时,rake db:seed我得到了一个我需要运行的错误rake db:migrate。我尝试在本地运行应用程序并得到了这个

事件

这是在某个终端的某个地方,看起来很相关

ActionView::Template::Error (Could not find table 'refinery_events'):
1: <%= render 'refinery/admin/search_header', :url => refinery.events_admin_events_path %>
2: <div class='pagination_container'>
3:   <% if @events.any? %>
4:     <%= render 'events' %>
5:   <% else %>
6:     <p>

我也收到了这个关于作者的错误,但教程没有提到它

Using refinerycms-events (1.0) from source at vendor/extensions
refinerycms-events at /Users/juan.gallardo/Desktop/myfiles/test-projects/rickrockstar/vendor/extensions/events did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  authors may not be empty

Using refinerycms-singular_model_names (1.0) from source at vendor/extensions
refinerycms-singular_model_names at /Users/juan.gallardo/Desktop/myfiles/test-projects/rickrockstar/vendor/extensions/singular_model_names did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  authors may not be empty

所以我再次经历了这个过程

jgallardo:rickrockstar juan.gallardo$ rails generate refinery:events
    rake  refinery_events:install:migrations
  append  db/seeds.rb
jgallardo:rickrockstar juan.gallardo$ rake db:migrate
rake aborted!

这次我清楚地看到了,rake aborted但无论如何都试过了

jgallardo:rickrockstar juan.gallardo$ rake db:seed
You have 2 pending migrations:
  20130826173639 CreateSingularModelNamesSingularModelNames
  20130826173941 CreateEventsEvents
Run `rake db:migrate` to update your database then try again.

我在 Google 上搜索了未决迁移的含义,我看到有人告诉其他有类似问题的人要运行,--trace所以这是我的尝试

jgallardo:rickrockstar juan.gallardo$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
/Users/juan.gallardo/Desktop/myfiles/test-projects/rickrockstar/db/migrate/20130826173639_create_singular_model_names_singular_model_names.refinery_singular_model_names.rb:7: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
  t.type :[attribute
           ^
/Users/juan.gallardo/Desktop/myfiles/test-projects/rickrockstar/db/migrate/20130826173639_create_singular_model_names_singular_model_names.refinery_singular_model_names.rb:8: syntax error, unexpected ..., expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
  t.string :...]
               ^
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:537:in `load_migration'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:533:in `migration'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:528:in `migrate'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:775:in `call'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:775:in `ddl_transaction'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:719:in `block in migrate'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:700:in `each'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:700:in `migrate'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:570:in `up'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/migration.rb:551:in `migrate'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/juan.gallardo/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/bin/rake:23:in `load'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/bin/rake:23:in `<main>'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/Users/juan.gallardo/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
4

2 回答 2

1

如果您阅读并思考他们在说什么,而不是仅仅将其中的一部分复制并粘贴到您的终端中,则教程效果最好。

在这种情况下,您复制和粘贴的示例是:

rails generate refinery:engine singular_model_name attribute:type [attribute:type ...] 

但是,当您生成事件扩展时,您成功地将其替换为正确的语法,所以那个没有问题。

删除标题为 CreateSingularModelNamesSingularModelNames 的迁移及其整个相应的扩展。您复制粘贴的示例语法不会生成有效的 Ruby。

于 2013-08-26T20:15:39.803 回答
0

正如在接受的答案中指出的那样,我复制粘贴了错误的代码,如下所示 6.2

示例代码

我最终只是删除了项目并重新开始。但后来我从下面复制粘贴

复制意大利面

之后一切正常。

于 2013-08-28T17:50:59.580 回答