Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

公開日 : 2018-02-04

RailsでワードプレスっぽいCMSを動かしてみた ~Refinery~

このエントリーをはてなブックマークに追加

RefineryというRuby on Rails用のCMSをインストールしてみた


Wordpressよりも自由度の高いことをしたい!けどエンドユーザーでも簡単に登録できるようにしたい!と思っているので、RailsでCMSを動かしてみようと思います。Refineryというgemを使って、簡単なブログを作ってみました!



参考にしたのはこの辺のサイト







管理画面をbootstrapでいい感じにする動画も見つけた。







インストール


まずは適当なアプリを作っておきます。

$ rails new cms

Gemfileにrefineryを追加します。


Gemfile

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

gem "refinerycms" #追加
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gemをインストールします。

$ bundle install 

refineryでブログを作成します。

$ rails generate refinery:blog

マイグレートして

$rake db:migrate

初期データを入れます

$rake db:seed

うまくインストールされているか、確認します。
ルーティングを見てみます。管理画面が作られているのがわかりますね。

$ rake routes
  Prefix Verb URI Pattern Controller#Action
refinery      /           Refinery::Core::Engine

Routes for Refinery::Core::Engine:
                                     login GET    /refinery/login(.:format)                  refinery/authentication/devise/sessions#new
                                    logout GET    /refinery/logout(.:format)                 refinery/authentication/devise/sessions#destroy
                                new_signup GET    /refinery/users/register(.:format)         refinery/authentication/devise/users#new
                                    signup POST   /refinery/users/register(.:format)         refinery/authentication/devise/users#create
    new_authentication_devise_user_session GET    /refinery/users/login(.:format)            refinery/authentication/devise/sessions#new
        authentication_devise_user_session POST   /refinery/users/login(.:format)            refinery/authentication/devise/sessions#create
destroy_authentication_devise_user_session DELETE /refinery/users/logout(.:format)           refinery/authentication/devise/sessions#destroy
   new_authentication_devise_user_password GET    /refinery/users/password/new(.:format)     refinery/authentication/devise/passwords#new
  edit_authentication_devise_user_password GET    /refinery/users/password/edit(.:format)    refinery/authentication/devise/passwords#edit
       authentication_devise_user_password PATCH  /refinery/users/password(.:format)         refinery/authentication/devise/passwords#update
                                           PUT    /refinery/users/password(.:format)         refinery/authentication/devise/passwords#update
                                           POST   /refinery/users/password(.:format)         refinery/authentication/devise/passwords#create
         authentication_devise_admin_users GET    /refinery/users(.:format)                  refinery/authentication/devise/admin/users#index
                                           POST   /refinery/users(.:format)                  refinery/authentication/devise/admin/users#create
      new_authentication_devise_admin_user GET    /refinery/users/new(.:format)              refinery/authentication/devise/admin/users#new
     edit_authentication_devise_admin_user GET    /refinery/users/:id/edit(.:format)         refinery/authentication/devise/admin/users#edit
          authentication_devise_admin_user PATCH  /refinery/users/:id(.:format)              refinery/authentication/devise/admin/users#update
                                           PUT    /refinery/users/:id(.:format)              refinery/authentication/devise/admin/users#update
                                           DELETE /refinery/users/:id(.:format)              refinery/authentication/devise/admin/users#destroy
                                 wymiframe GET    /wymiframe(/:id)(.:format)                 refinery/fast#wymiframe
                                      root GET    /                                          refinery/pages#home
                                      page GET    /pages/:id(.:format)                       refinery/pages#show
                 pages_admin_preview_pages POST   /refinery/pages/preview(.:format)          refinery/pages/admin/preview#show
                  pages_admin_preview_page PATCH  /refinery/pages/preview/*path(.:format)    refinery/pages/admin/preview#show
                           admin_edit_page GET    /refinery/pages/*path/edit(.:format)       refinery/admin/pages#edit
                      admin_children_pages GET    /refinery/pages/*path/children(.:format)   refinery/admin/pages#children
                         admin_update_page PATCH  /refinery/pages/*path(.:format)            refinery/admin/pages#update
                         admin_delete_page DELETE /refinery/pages/*path(.:format)            refinery/admin/pages#destroy
              update_positions_admin_pages POST   /refinery/pages/update_positions(.:format) refinery/admin/pages#update_positions
                               admin_pages GET    /refinery/pages(.:format)                  refinery/admin/pages#index
                                           POST   /refinery/pages(.:format)                  refinery/admin/pages#create
                            new_admin_page GET    /refinery/pages/new(.:format)              refinery/admin/pages#new
                           edit_admin_page GET    /refinery/pages/:id/edit(.:format)         refinery/admin/pages#edit
                                admin_page PATCH  /refinery/pages/:id(.:format)              refinery/admin/pages#update
                                           PUT    /refinery/pages/:id(.:format)              refinery/admin/pages#update
                                           DELETE /refinery/pages/:id(.:format)              refinery/admin/pages#destroy
               link_to_admin_pages_dialogs GET    /refinery/pages_dialogs/link_to(.:format)  refinery/admin/pages_dialogs#link_to
                          admin_page_parts POST   /refinery/page_parts(.:format)             refinery/admin/page_parts#create
                       new_admin_page_part GET    /refinery/page_parts/new(.:format)         refinery/admin/page_parts#new
                           admin_page_part DELETE /refinery/page_parts/:id(.:format)         refinery/admin/page_parts#destroy
                                           GET    /system/resources/*dragonfly(.:format)     <Dragonfly::App name=:refinery_resources >
                    insert_admin_resources GET    /refinery/resources/insert(.:format)       refinery/admin/resources#insert
                           admin_resources GET    /refinery/resources(.:format)              refinery/admin/resources#index
                                           POST   /refinery/resources(.:format)              refinery/admin/resources#create
                        new_admin_resource GET    /refinery/resources/new(.:format)          refinery/admin/resources#new
                       edit_admin_resource GET    /refinery/resources/:id/edit(.:format)     refinery/admin/resources#edit
                            admin_resource PATCH  /refinery/resources/:id(.:format)          refinery/admin/resources#update
                                           PUT    /refinery/resources/:id(.:format)          refinery/admin/resources#update
                                           DELETE /refinery/resources/:id(.:format)          refinery/admin/resources#destroy
                                           GET    /system/images/*dragonfly(.:format)        <Dragonfly::App name=:refinery_images >
                       insert_admin_images GET    /refinery/images/insert(.:format)          refinery/admin/images#insert
                              admin_images GET    /refinery/images(.:format)                 refinery/admin/images#index
                                           POST   /refinery/images(.:format)                 refinery/admin/images#create
                           new_admin_image GET    /refinery/images/new(.:format)             refinery/admin/images#new
                          edit_admin_image GET    /refinery/images/:id/edit(.:format)        refinery/admin/images#edit
                               admin_image PATCH  /refinery/images/:id(.:format)             refinery/admin/images#update
                                           PUT    /refinery/images/:id(.:format)             refinery/admin/images#update
                                           DELETE /refinery/images/:id(.:format)             refinery/admin/images#destroy
                                   message GET    /refinery/message(.:format)                refinery/fast#message
                                admin_root GET    /refinery(.:format)                        refinery/admin/core#index
                             admin_dialogs GET    /refinery/dialogs(.:format)                refinery/admin/dialogs#index
                              admin_dialog GET    /refinery/dialogs/:id(.:format)            refinery/admin/dialogs#show
                                           GET    /sitemap.xml(.:format)                     refinery/sitemap#index {:format=>"xml"}
                                           GET    /refinery/*path(.:format)                  refinery/admin#error_404
                           marketable_page GET    /*path(.:format)                           refinery/pages#show



サーバーを起動します

$ rails s

そうすると、リダイレクトされてユーザー登録ページに移動されます。




ページを作成することができたり、子文書を作成できたりします。






とりあえず、今日はここまで。今度は作成したデータを、管理者画面ではなく、本番の画面に反映する方法を解説したいと思います。


スポンサーリンク