How can I create my own CMS in a Rails 3.2 application using rails_admin, etc.?

I have created a website for the client, but they want to be able to digitize the contents of the web page as images and text. I tried, tried and tried, but I could not get something like RefineryCMS as a plugin to work in my application.

I read somewhere about someone who created their own CMS using rails_admin, devise, ckeditor, kaminari, etc. But how can I create my own CMS / administrative area so that the client can recoup the content without messing with the code or finding out some code?

I have Ruby 1.9.2 and Rails 3.2.2. Does anyone know how I can do this, get my own CMS to connect to this existing application? Is there some kind of tutorial, or can someone explain this to me? Thanks in advance!

+3
source share
2 answers

Rails_admin is very good, but often too much for what some people want. Developing your own admin section is quite simple.

How to create your own RESTful admin section with Rails 3.2

Create your own Admin section with CRUD for all models, including nested resources, using namespaces.

Example - admin section for a blog - Models: post, comment (attached message resource)

I assume you have a basic blog application. See http://guides.rubyonrails.org/getting_started.html to set it all up.

The first step is to create an administrator section and a controller

rails g controller admin/admin 

This will create an empty controller from which all of our Admin controllers will inherit. And he will also create views / admin / admin / index.html.erb, which can act as a toolbar.

Creating Admin Controllers

 rails g controller admin/posts rails g controller admin/comments 

This will create an empty Admin :: PostsController and Admin :: CommentsController in the admin namespace

Step 2 - add a namespace for admin controllers Go to config / routes.rb and add the following

  namespace :admin do root to: "admin#index" resources :posts do resources :comments, :only => [:create, :destroy] end end 

Step 3 - Editing administrators and controllers files to work with the admin namespace Now we have everything we need to make working with the administrator controller, and not with the interface.

Change the inheritance of all Admin :: * controllers.

 class Admin::PostsController < ApplicationController => class Admin::PostsController < Admin::AdminController 

and

 class Admin::CommentsController < ApplicationController => class Admin::CommentsController < Admin::AdminController 

copy all templates from applications / views / messages to the application / views / admin / posts copy all templates from applications / views / comments to the application / views / admin / comments copy all functions from posts_controller.rb to admin / posts_controller.rb copy all functions from comment_controller.rb to admin / comments_controller.rb

Add a link to the views /admin/admin/index.html.erb for each model for which you would like to have an Admin CRUD controld. For example, mail.

 <%= link_to "Posts", admin_posts_path %> 

Edit admin / posts_controller.rb. Change 3 calls to redirect_to to work with the admin namespace. Ways to create and update:

 redirect_to @post => redirect_to [:admin, @post] 

Destruction Method:

 redirect_to posts_url => redirect_to admin_posts_url 

Make the same changes in all the templates so that they work inside the admin namespace. You need to make the following changes:

post / _form.html.erb:

 form_for(@post) => form_for([:admin, @post]) 

post / edit.html.erb, index.html.erb, new.html.erb and show.html.erb find all instances:

 <%= link_to 'Show', @post %> => <%= link_to 'Show', [:admin, @post] %> posts_path => admin_posts_path edit_post_path(@post) => edit_admin_post_path(@post) new_post_path => new_admin_post_path <%= render "comments/form" %> => <%= render "admin/comments/form" %> 

comment / _comment.html.erb

 <%= link_to 'Destroy Comment', [comment.post, comment],... => <%= link_to 'Destroy Comment', [:admin, comment.post, comment],... 

comment / _form.html.erb change:

 <%= form_for([@post, @post.comments.build]) do |f| %>=> <%= form_for([:admin, @post, @post.comments.build]) do |f| %> 

That's all. Now you have a / admin control panel with a link to / admin / posts and available CRUD actions.

Go to http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding . His solution since 2008 is still very relevant, however, obviously, there are some differences from Rails 3.2 to which this answer refers; including invested resources.

+12
source

So you want rails_admin ...

Set gemstone

 $ gem 'rails_admin' 

follow

 $ bundle install 

then generate content

 $ rails generate rails_admin:install 

then

 $ rails server 

Now you can go to the admin panel on the .com / admin domain Perhaps you should look a bit at https://github.com/sferik/rails_admin . If you have much more questions than before, you should first think about learning. Rails is not so easy to use, since loading the contents of wordpress.zip into some db settings and doing it.

0
source

Source: https://habr.com/ru/post/908239/


All Articles