Ruby on Rails 中的后端管理

发布于 2024-07-05 13:28:33 字数 305 浏览 7 评论 0原文

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

当播放器已在使用中并且您希望尽可能避免影响其任何相关文件时,如何创建 admin_players 界面?

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

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.

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤者何惧 2024-07-12 13:28:33

我非常广泛地使用 Streamlined。

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

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

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

I have used Streamlined pretty extensively.

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 .

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
耳根太软 2024-07-12 13:28:33

我认为命名空间是解决您遇到的问题的方法:

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

它将创建路由 admin_customersnew_admin_customers 等。

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

./script/generate rspec_controller admin/admin

class Admin::AdminController < ApplicationController

  layout "admin"
  before_filter :login_required
end

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

./script/generate rspec_controller admin/customers

并使其继承于您的 ApplicationController:

class Admin::CustomersController < Admin::AdminController

这将在 app/views/admin/customers 中查找视图
并且预计布局位于 app/views/layouts/admin.html.erb 中。

然后,您可以使用您喜欢的任何插件或代码来实际执行管理、简化、ActiveScaffold,以及我个人喜欢使用 resourcecs_controller 的任何内容,因为如果您使用 REST 风格的架构,强迫自己走这条路可以在其他地方节省大量时间。 不过,如果您继承了该应用程序,那么现在还没有什么意义。

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.

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

./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:

class Admin::CustomersController < Admin::AdminController

This will look for views in app/views/admin/customers
and will expect a layout in app/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 REST style 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.

千紇 2024-07-12 13:28:33

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文