在Rails中添加CMS功能的LocomotiveCMS!

顺便说一句,LocomotiveCMS是Rails CMS,当我在谷歌上搜索时,是我最先找到的东西。
我想要做一个在Rails上的应用程序,并让使用者来使用,所以我一直在寻找这样的软件。
虽然WordPress也可以,但是相对于PHP,我认为Ruby更好,这就成为了其中一个选择。

除了LocomotiveCMS Engine之外,LocomotiveCMS还附带了一个名为Locomotive Wagon的命令行工具,它可以轻松创建博客,但需要注意的是它并不像Rails一样运行。

参考サイトとしては、以下の2つがとても役立った。

    • LocomotiveCMS本家

http://www.locomotivecms.com/
http://doc.locomotivecms.com/guides/get-started/install-engine

管理ページを日本語化してくれた神のブログ

http://xxxcaqui.hatenablog.com/entries/2013/04/12

本地环境使用Mac进行配置,服务器使用Heroku作为默认选项。

事前准备:MongoDB的配置

首先,安装软件。

$ brew install mongodb

以下是启动设置。

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/mongodb/2.2.3-x86_64/homebrew.mxcl.mongodb.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

确认是否恰当地站起来了。

$ ps x | grep mongodb
 14968   ??  S      0:00.41 /usr/local/opt/mongodb/mongod run --config /usr/local/etc/mongod.conf
 14983 s004  R+     0:00.00 grep --color=auto mongodb

创建一个新的Rails项目。

    • 現状railsは3.2系列で無いと動かない。4.0系列で作られると困る

 

    • DBはactive_recordじゃなく、mongodbを使う

 

    テストはrspecを使いたい。

因此,制作如下。

$ rails _3.2.13_ new loco_site --skip-active-record --skip-test-unit --skip-bundle

或者

$ rails _3.2.13_ new loco_site -O -T -B

在本地上运行LocomotiveCMS。

稍微修改Gemfile。

    • rubyのバージョンを指定。(しないと後々HerokuでWarningが出る。)

locomotive_cms, unicorn, rspec-railsを追加。
locomotive_cmsに従ってassets groupにcompass-railsを追加。

本当はpryとかbetter-errorsとかも追加するけどまぁいいや。

コメントを取った後のGemfileは以下のようになる。

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '3.2.13'

gem 'locomotive_cms', require: 'locomotive/engine'
gem 'thin'
gem 'rspec-rails'

group :assets do
  gem 'compass-rails',  '~> 1.0.2'
  gem 'sass-rails',     '~> 3.2.4'
  gem 'coffee-rails',   '~> 3.2.2'
  gem 'uglifier',       '~> 1.2.4'
end

gem 'jquery-rails'

書き換えたら、

$ bundle install

Rspecの設定と

$ rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb

產生LocomotiveCMS的設定。

$ rails g locomotive:install
      create  config/initializers/locomotive.rb
      create  config/initializers/carrierwave.rb
      create  config/initializers/dragonfly.rb
      create  config/mongoid.yml
       route  
  mount Locomotive::Engine => '/locomotive', as: 'locomotive' # you can change the value of the path, by default set to "/locomotive"

      remove  public/index.html
===============================================================================

The Locomotive Engine has been correctly installed in your Rails application.

  1. Edit the main config files:

    - config/initializers/locomotive.rb
    - config/initializers/carrierwave.rb
    - config/initializers/dragonfly.rb
    - config/mongoid.yml
    - config/devise.yml
    - config/routes.rb

  2. Launch the server

    > bundle exec unicorn_rails

  3. Open your browser

    > open localhost:8080

  4. Follow the installation wizard steps

  5. Enjoy !

===============================================================================

当然地启动并尝试,没有必要调整任何设置。

$ bundle exec unicorn_rails
I, [2013-07-07T14:49:13.214872 #62661]  INFO -- : listening on addr=0.0.0.0:8080 fd=9
I, [2013-07-07T14:49:13.215010 #62661]  INFO -- : worker=0 spawning...
I, [2013-07-07T14:49:13.216376 #62661]  INFO -- : master process ready
I, [2013-07-07T14:49:13.217791 #62681]  INFO -- : worker=0 spawned pid=62681
I, [2013-07-07T14:49:13.218408 #62681]  INFO -- : Refreshing Gem list
There is a configuration error with the current mongoid.yml.

Problem:
  No sessions configuration provided.
Summary:
  Mongoid's configuration requires that you provide details about each session that can be connected to, and requires in the sessions config at least 1 default session to exist.
Resolution:
  Double check your mongoid.yml to make sure that you have a top-level sessions key with at least 1 default session configuration for it. You can regenerate a new mongoid.yml for assistance via `rails g mongoid:config`.

 Example:
   development:
     sessions:
       default:
         database: mongoid_dev
         hosts:
           - localhost:27017

と言ったエラーが出る。全くEnjoy出来ない。mongoid.ymlの設定の仕方が昔と変わったみたい。

首先,错误信息非常友好。

rails g mongoid:config

只需覆盖config/mongoid.yml文件,问题就会解决。

open localhost:8080

只要在浏览器中输入localhost:8080,应该会出现向导界面!

结束了!!