1

我需要一个用于管理的后端,我尝试了 RailsAdminActiveAdmin,但是自定义级别有限,并找到了 gem admin_interface,它给了我想要的选项。

这是我项目的结构

├── app
│   ├── assets
│   ├── controllers
│   │   ├── admin
│   │   │   ├── locations_controller.rb
│   │   ├── application_controller.rb
│   │   ├── locations_controller.rb
│   ├── models
│   │   ├── location.rb

class LocationsController < InheritedResources::Base
  respond_to :html, :json
  def index
    @locations = Location.all
    @json = Location.all.to_gmaps4rails
  end
end

class Admin::LocationsController < Admin::ResourceController  
  # See admin/resource_controller.rb for more info..
end

class Admin::ResourceController < Admin::BaseController

  inherit_resources # gem
  defaults :route_prefix => 'admin'

  # inherited_resources options
  # nested_belongs_to :user, :optional => true

  def destroy_all
    destroyed_resources = resource_class.destroy_all(:id => params[:ids])
    flash[:notice] = "#{destroyed_resources.size} objects destroyed."
    redirect_to :back
  end

protected

  # Overwrites inherited_resources gem version.
  # Use meta_search and kaminari gem to load collection
  def collection
    @search ||= end_of_association_chain.search(params[:q])
    get_collection_ivar || begin
      c = @search.result.page(params[:page]).per(params[:per])
      set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c)
    end
  end
end

正如我可以做的那样,让admin>application_controller.rb继承自application_controller.rb。我想要@json = Lugar.all.to_gmaps4rails这也可用于管理控制器?

提前致谢。

4

0 回答 0