简体   繁体   English

关于Rails插件/引擎

[英]about rails plugins/engines

I am looking at rails plugins to help me modularize my application. 我正在寻找Rails插件来帮助我模块化我的应用程序。 I have some basic questions that I am confused about. 我有一些基本的问题我很困惑。

Can a rails plugin have its own DB? Rails插件可以有自己的数据库吗? My application is very little traffic, for internal use, so I am fine with the idea of separate sqlite DB's for each plugin. 我的应用程序的流量很小,仅供内部使用,因此我对每个插件使用单独的sqlite DB的想法很好。 When I do a "rails plugin new" even if I use --full, there is no database.yml generated. 即使使用--full,当我执行“新的Rails插件”时,也不会生成database.yml。 If I create one and do a rake db:create, no sqlite db is created. 如果我创建一个并执行rake db:create,则不会创建sqlite db。

Is there a good tutorial available for creating a rails plugin with rails 3.2? 有没有可用的Rails 3.2创建Rails插件的好教程? Most I find are older and use the enginex gem which I think is now built into rails. 我发现的大多数都比较老,并且使用的是enginex gem,我认为它现在已内置在导轨中。

Can you run your plugin as a standalone app for testing, ie using WEBrick? 您可以将插件作为独立应用程序运行以进行测试,即使用WEBrick吗? When I run "rails server" in my plugin directory, it just says "Error: Command not recognized". 当我在插件目录中运行“ rails服务器”时,它只会显示“错误:无法识别命令”。

I guess that's it, I am just confused on how to begin. 我想就是这样,我只是对如何开始感到困惑。

Creating Migrations 创建迁移

The Rails Guide "Getting Started with Engines" instructs you to use 'rails g model post' from the root directory for your engine. Rails指南“引擎入门”指导您使用引擎根目录中的“ rails g model post”。

Getting Started with Engines 引擎入门

If you do this, it will create the db/migrate folder for you with the migration inside of it. 如果这样做,它将为您创建db / migrate文件夹,并在其中进行迁移。

$ rails g model post
  invoke  active_record
  create    db/migrate/20120517184738_create_my_engine_posts.rb
  create    app/models/my_engine/post.rb
  invoke    test_unit
  create      test/unit/my_engine/post_test.rb
  create      test/fixtures/my_engine/posts.yml

You can also generate migrations directly just the same, just as you do with a Rails app. 您也可以像使用Rails应用一样直接直接生成迁移。

$ rails g migration AddMyEngineTable
  invoke  active_record
  create    db/migrate/20120517185241_add_my_engine_table.rb

Running Rails Server 运行Rails服务器

The Rails Guide also states to run 'rails s' from test/dummy, not from the root of your engine directory. Rails指南还声明从test / dummy而不是从引擎目录的根目录运行“ rails s”。

I see that from an ASCIICast on the subject which covered Rails 3.1 RC5 that you used to be able to run 'rails s' from the root directory of your engine/gem. 我从涵盖了Rails 3.1 RC5的主题的ASCIICast中看到,您曾经能够从engine / gem的根目录运行'rails s'。 This is no longer the case. 这已不再是这种情况。

From the Rails issue posted on Github three months ago it appears that they needed to keep the scope of the engine separate from the scope of the dummy app. 从三个月前在Github上发布的Rails问题看来,他们需要将引擎的范围与虚拟应用程序的范围分开。

Issue #4894: Mountable Engines Rails File 问题#4894:可安装引擎Rails文件

在短期内从引擎根目录开始:

test/dummy/script/rails s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM