一、开始ActiveAdmin

Active Admin是一个发布在RAILS3中使用的Gem。
1、我们为了快速开始我们对Active Admin的了解,我们首先安装它:
在你GemFile中添加gem 'activeadmin'
2、更新你的Gem
bundle install
3、运行installer
rails generate active_admin:install
4、安装的installer会创建一个initializer,这个initializer采用Active Admin默认的配置,把所有需要的配置都写进一个文件夹app/admin里面。
同时,这个时候会显示相关的配置信息,并按照配置信息完成相关指示操作。

Some setup you must do manually if you haven't yet:

1. Ensure you have defined default url options in your environments files. Here
     is an example of default_url_options appropriate for a development environment
     in config/environments/development.rb:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

In production, :host should be set to the actual host of your application.

2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:

root :to => "home#index"

3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:

<p class="notice"><%= notice %></p>
       <p class="alert"><%= alert %></p>

4. If you are deploying Rails 3.1+ on Heroku, you may want to set:

config.assets.initialize_on_precompile = false

On config/application.rb forcing your application to not access the DB
     or load models when precompiling your assets.

5. You can copy Devise views (for customization) to your app by running:

rails g devise:views


完成以上操作,我们还需要配置邮件服务器
编辑config/initializers/devise.rb

  # Configure the e-mail address which will be shown in DeviseMailer.
  config.mailer_sender ="xxx@126.com"   #换成你的邮箱,最好不要是gmail

编辑config/environments/development.rb
 # Don't care if the mailer can't send

  config.action_mailer.raise_delivery_errors =true  #此处改为true
  config.action_mailer.default_url_options = {:host => "localhost:3000" } #刚才devise的提示中提到这一句
  config.action_mailer.delivery_method =:smtp
  config.action_mailer.smtp_settings = {
    :address=> "smtp.126.com",
    :port=> 25,
    :domain=> "126.com",
    :authentication=> :login,
    :user_name=> "xxx@126.com",#你的邮箱
    :password=> "xxxxxx" #你的密码
  }

5、迁移你的db ,rake db:migrate,然后运行rails server 。

6、然后打开浏览器,输入 localhost:3000/admin 进行访问。
用户名: admin@example.com
密码:password
7、添加你的model
rails g model  [MyModelName]  name:string title:string content:text
8、将model放到admin目录中去 
rails generate active_admin:resource [MyModelName]
这个命令会创建一个文件app/admin/my_model_names.rbl来配置你的resource。
刷新你的浏览器,看看这个时候的界面是怎么样的。
二、ActiveAdmin更新
你可以键入如下命令进行对它的升级
rails generate active_admin:assets
如果提示:uninitialized constant Admin::DashboardController
这个时候,需要dashboard view(app/admin/dashboards.rb)和初始化的时候一样。
三、下一步
1、最好得到的阅读文档的地方:activeadmin.info/documentation.html.
2、AcitiveAdmin 的示例网址:demo.activeadmin.info
3、如果有问题,在这个网站的邮箱列表(groups.google.com/group/activeadmin)中发邮件。
四、补充说明
1、我在实际安装过程中,安装了很多的东西,这里我把安装过程中的gem一并写下来,就按gemfile里写的格式写下来。
gem 'activeadmin','0.5.1'
gem 'arbre','1.0.1'
gem 'bourbon','1.0.0'
gem 'devise','1.5.4'
gem 'formtastic','2.1.0'
gem 'has_scope','0.5.1'
gem 'inherited_resources','1.3.1'
gem 'meta_search','1.1.3'
gem 'orm_adapter','0.0.3'
gem 'polyamorous','0.5.0'
gem 'responders','0.6.5'
gem 'warden','1.1.1'
2、install过后,截图纪念一下

五、完成安装过后,又开始我们的下一个旅程——订制自己的后台。
1、给menu,index页面,form页面还有filter和help添加一些内容和中文命名
ActiveAdmin.register Post  do 
  menu :label => "文章管理"
    index  do  
    column "标题",:title                  
    column "作者",:name      
    column "内容",:content                 
    default_actions    
  end        
  
  filter :title ,:label=>"标题"
  filter :name ,:label=>"作者"
  filter :content ,:label=>"内容"
  
  form do |f|
    f.inputs "添加标题和作者" do
      f.input :title,:label=>"标题"
      f.input :name,:label=>"作者"
    end
    f.inputs "添加内容" do
      f.input :content,:label=>"文章内容"
    end
    f.buttons
  end
  
  sidebar :help,:only => :index do
  "如果你对网站后台管理有问题,请联系CreateByRails@yeah.net"
  end
 
end
 
六、汉化页面

1、现在将整个页面汉化一下

首先,我们已经在config/application.rb里配置了local为 zh-CN,

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
     config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
     config.i18n.default_locale = "zh-CN"

然后到http://github.com/tsechingho/rails-i18n/blob/master/rails/locale/zh-CN.yml

下载已经配置好的中文包到config/locales里,这样,rails的中文化已经做好了。

2、devise的汉化

到该Wiki去下载汉化包 devise.zh-CN.yml

https://github.com/plataformatec/devise/wiki/I18n

然后删除原来的devise.en.yml

3、解决编码问题

在你需要显示汉语的*.rb文件中 ,添加一句代码

#encoding:utf-8

Rails中activeAdmin的使用的更多相关文章

  1. Rails中的MIME类型

    layout title date comments categories post rails的中的MIME类型 2014-09-08 21:40 true ruby Rails开发中经常使用不同的 ...

  2. rails 中 create, new, build, save 的用法以及误区汇总

    自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源 ...

  3. rails中weill_paginate的paginate方法中不能使用额外参数的解决办法

    我们知道高版本中的rails中的分页功能已经放在will_paginate这个gem中,我们在控制器方法中往往需要调用其paginate方法来实现分页数据集控制,举个例子:正常的情况我们想要每页显示1 ...

  4. rails中accepts_nested_attributes_for应用

    Model: class Blog < ActiveRecord::Base has_many :strip_rules accepts_nested_attributes_for :strip ...

  5. rails中params[:id]与params["id"]分析

    写这个帖子的缘由是因为在页面参数传到rails的controller时用params[:]和params[""]都可以取到值: [1] pry(#<BooksControll ...

  6. Rails中的增删改查

      1.        rails中类与对象与SQL中表与行的关系 rails中提供了对象关系映射(ORM),将模型类映射至表,模型类的关联表名是类名小写后的复数形式,如类名Order,对应的表名为o ...

  7. rails中path、url路径解析,routes信息,form_for剖析,link_to示例,路由实例说明

    原创,转载请注明http://www.cnblogs.com/juandx/p/3963023.html  rails中path.url路径解析,routes信息,form_for剖析,link_to ...

  8. rails 中 create, new, build, save 的用法以及误区汇总 (转)

    自己很初级,初级的不能再初级,所以初次接触rails的时候,对于里面的create,new,build等方法不是很了解,用的很混乱,导致经常出现不必要的bug,很苦恼,决定,总结一下,结合网上已有资源 ...

  9. rails中使用CarrierWave实现文件上传的功能

    之前在用django写blog的时候头像上传和头像预览都是使用原生的js实现的,之前也有写了一篇blog.好了开始进入正题 rails中实现头像上传十分的方便,只要通过CarrierWave这个gem ...

随机推荐

  1. 网友写的解决uniGUI限制的方法

    群友写的解决uniGUI试用版限制修改SessionTimeOut,思路很精巧,贴过来分享,感谢朋友的奉献.当然,如果真正用uniGUI实做项目,买份正版是正道! var   UniServerOpt ...

  2. Thread in depth 4:Synchronous primitives

    There are some synchronization primitives in .NET used to achieve thread synchronization Monitor c# ...

  3. linux系统编程:setjmp和longjmp函数用法

    #include <stdio.h> #include <setjmp.h> //jmp_buf:数组,保存栈信息即运行环境 jmp_buf buf; double Divid ...

  4. BCP IN示例

    参考:http://www.cnblogs.com/qanholas/archive/2011/07/05/2098616.html bcp {dbtable | query} {in | out | ...

  5. 前端项目打包工具weexpack的安装

    最下面是本人安装时候的系统环境,本篇文章只限于参考,不一定非得是这样,原因你懂得. 打包的过程中出现的问题 1.执行到weexpack run android的时候,到了resolving class ...

  6. CryptoJS与C#AES加解密互转

    CryptoJS下载地址: https://code.google.com/archive/p/crypto-js/downloads http://download.csdn.net/detail/ ...

  7. day 113 爬虫框架

    基础配置

  8. ovs 源mac, 目的src 互换

    push:NXM_OF_ETH_SRC[],push:NXM_OF_ETH_DST[],pop:NXM_OF_ETH_SRC[],pop:NXM_OF_ETH_DST[] 1:把src mac推到栈顶 ...

  9. Exp2 后门原理与实践 20164321 王君陶

    Exp2 后门原理与实践 20164321 王君陶 一.实验内容 基础问题回答: 1.例举你能想到的一个后门进入到你系统中的可能方式? 答:通过漏洞,点击陌生链接,或者浏览不良网页挂马. 2.例举你知 ...

  10. CTFcrackTools-V3 – 一款旨在帮助 CTFer 在 CTF 中发挥作用的一个框架

    CTFcrackTools-V3 CTFcrackTools重置版 作者:米斯特安全-林晨.摇摆.奶权 米斯特安全团队首页:http://www.hi-ourlife.com/ 部分插件来源:希望团队 ...