Ruby on Rails 中的后端管理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/107674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:40:30  来源:igfitidea点击:

Backend administration in Ruby on Rails

ruby-on-railsadmingeneratorscaffoldingbackend

提问by srboisvert

I'd like to build a real quick and dirty administrative backend for a Ruby on Rails application I have been attached to at the last minute. I've looked at activescaffold and streamlined and think they are both very attractive and they should be simple to get running, but I don't quite understand how to set up either one as a backend administration page. They seem designed to work like standard Ruby on Rails generators/scaffolds for creating visible front ends with model-view-controller-table name correspondence.

我想为我在最后一刻附加的 Ruby on Rails 应用程序构建一个真正快速而肮脏的管理后端。我查看了 activescaffold 和精简版,认为它们都非常有吸引力,而且运行起来应该很简单,但我不太明白如何将其中任何一个设置为后端管理页面。它们似乎旨在像标准的 Ruby on Rails 生成器/脚手架一样工作,用于创建具有模型-视图-控制器-表名称对应关系的可见前端。

How do you create a admin_players interface when players is already in use and you want to avoid, as much as possible, affecting any of its related files?

当玩家已经在使用并且您想尽可能避免影响其任何相关文件时,您如何创建 admin_players 界面?

The show, edit and index of the original resource are not usuable for the administrator.

管理员无法使用原始资源的显示、编辑和索引。

回答by Laurie Young

I think namespaces is the solution to the problem you have here:

我认为命名空间是您在这里遇到的问题的解决方案:

map.namespace :admin do |admin|
    admin.resources :customers
end

Which will create routes admin_customers, new_admin_customers, etc.

这将创建路线admin_customersnew_admin_customers等等。

Then inside the app/controllerdirectory you can have an admindirectory. Inside your admin directory, create an admin controller:

然后在app/controller目录中,您可以拥有一个admin目录。在您的 admin 目录中,创建一个管理控制器:

./script/generate rspec_controller admin/admin

class Admin::AdminController < ApplicationController

  layout "admin"
  before_filter :login_required
end

Then create an admin customers controller:

然后创建一个管理员客户控制器:

./script/generate rspec_controller admin/customers

And make this inhert from your ApplicationController:

并从您的 ApplicationController 继承:

class Admin::CustomersController < Admin::AdminController

This will look for views in app/views/admin/customersand will expect a layout in app/views/layouts/admin.html.erb.

这将app/views/admin/customersapp/views/layouts/admin.html.erb.

You can then use whichever plugin or code you like to actually do your administration, streamline, ActiveScaffold, whatever personally I like to use resourcecs_controller, as it saves you a lot of time if you use a RESTstyle architecture, and forcing yourself down that route can save a lot of time elsewhere. Though if you inherited the application that's a moot point by now.

然后,您可以使用您喜欢的任何插件或代码来实际进行管理、简化、ActiveScaffold,无论我个人喜欢使用什么resourcecs_controller,因为如果您使用REST风格的架构,它会为您节省大量时间,并且强迫自己走这条路可以在别处节省大量时间。但是,如果您继承了该应用程序,那么现在就没有实际意义了。

回答by phoet

Do check out active_admin at https://github.com/gregbell/active_admin.

请在https://github.com/gregbell/active_admin 上查看 active_admin 。

回答by Toby Hede

I have used Streamlined pretty extensively.

我已经非常广泛地使用了Streamlined。

To get Streamline working you create your own controllers - so you can actually run it completely apart from the rest of your application, and you can even run it in a separate 'admin' folder and namespace that can be secured with .

为了让 Streamline 工作,你创建你自己的控制器——这样你实际上可以与应用程序的其余部分完全分开运行它,你甚至可以在一个单独的“admin”文件夹和命名空间中运行它,可以用 .

Here is the Customers controller from a recent app:

这是来自最近应用程序的客户控制器:

class CustomersController < ApplicationController
  layout 'streamlined'
  acts_as_streamlined       

  Streamlined.ui_for(Customer) do
    exporters :csv   
    new_submit_button :ajax => false 
    default_order_options :order => "created_at desc"   
    list_columns :name, :email, :mobile, :comments, :action_required_yes_no  
  end
end