一、开始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中activeAdmin的使用

    一.开始ActiveAdmin Active Admin是一个发布在RAILS3中使用的Gem. 1.我们为了快速开始我们对Active Admin的了解,我们首先安装它: 在你GemFile中添加g ...

  2. 开始了大概三四天的Rails学习之路

    最近因为一位极光推送朋友,我开始了大概三四天的Rails学习之路,最终达到的水平是可以比较轻松地做出大部分功能,然后自我感觉可以自如地按照Rails的设计思想去思考.由于编程的日益流行,我结识了越来越 ...

  3. [Rails学习之路]初识Ruby(一)

    Ruby是一门动态的.强类型的.纯面向对象的编程语言.它和Python非常相似,但比Python面向对象更加彻底.使用更加灵活.语法更加复杂.也更为有趣. 抛开做事情到底应该有多少种方法这个问题,我相 ...

  4. Rails中的缓存

    最近学习Rails. 看到如下代码: <% if notice %> <p id="notice"><%= notice %></p> ...

  5. Ruby学习资源汇总

    from:http://segmentfault.com/a/1190000000362058 Ruby 语言 Try Ruby: 无需在你的系统中安装.Ruby,只要通过浏览器便可立即体验 Ruby ...

  6. 【转】如何从零开始学会 Ruby on Rails?

    文章转自:http://huacnlee.com/blog/how-to-start-learning-ruby-on-rails/ 这个话题曾经给身边的很多朋友说过同样的话题,这里整理以下. 如果你 ...

  7. 如何从 0 开始学 ruby on rails (漫步版)

    如何从 0 开始学 ruby on rails (漫步版) ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架,简称 rails. 有很多人对  rails 感兴 ...

  8. 有意练习--Rails RESTful(一)

    书要反复提及<哪里有天才>在说,大多数所谓的天才是通过反复刻意练习获得. 当你的练习时间达到10000几个小时后,.你将成为该领域的专家. 近期在学习rails怎样实现RESTful We ...

  9. 如何从 0 开始学 Ruby on Rails

    如何从 0 开始学 Ruby on Rails (漫步版)Ruby 是一门编程语言,Ruby on Rails 是 Ruby 的一个 web 框架,简称 Rails. 有很多人对 Rails 感兴趣, ...

随机推荐

  1. Visual Studio for mac从入门到放弃1

    MAC  第一步:从微软官网下载:https://www.visualstudio.com/vs/visual-studio-mac/ 第二步:安装软件过程出现 It was not possible ...

  2. windows 10 RelativePanel

    The new RelativePanel implements a style of layout that is defined by the relationships between its ...

  3. c# in out ref关键字

    class in_out_ref { #region in 关键字 delegate void DContravariant<in A>(A argumen); static void o ...

  4. WPF自定义控件之列表滑动特效 PowerListBox

    列表控件是应用程序中常见的控件之一,对其做一些绚丽的视觉特效,可以让软件增色不少. 本人网上看过一个视频,是windows phone 7系统上的一个App的列表滚动效果,效果非常炫 现在在WPF上用 ...

  5. windows下用wampServer 为wordpress 搭建本地服务器运行环境

      1.准备wamp server wamp是windows apache mysql php 的首字母缩写,更新的wamp总能保证wordpress对服务器的要求 点此下载最新wamp 2.安装wa ...

  6. C博客的第1次作业--分支,顺序结构

    1.本章学习总结 1.1 思维导图 1.2本章学习体会,代码量学习体会 1.2.1学习体会 初步了解什么是C语言,明白了这门语言的基本运行功能.了解了关于c语言结构上,语法上的基本知识.下一步要进一步 ...

  7. django系列6--Ajax05 请求头ContentType, 使用Ajax上传文件

    一.请求头ContentType ContentType指的是请求体的编码类型,常见的类型共有三种: 1.application/x-www-form-urlencoded 这应该是最常见的 POST ...

  8. Python数据采集处理分析挖掘可视化应用实例

    距离上一次发Python的技术贴已经过去两年了,这两年大法初成,并在知乎谢了相关技术专栏.现在搬运如下,均为原创,转载需注明出处哦! https://zhuanlan.zhihu.com/p/2957 ...

  9. ElasticSearch关联查找

    ElasticSearch是一个基于Lucene的开源搜索引擎,支持全文检索,提供restful接口.在ES中,提供了类似于MongoDB的面向文档存储服务,这种面向文档的存储非常灵活,但是文档与文档 ...

  10. 【微信小程序】——wxss引用外部CSS文件及iconfont

    小程序引入外部文件的方式是:@import "*/*.wxss"; 因为业务需要,正在开发的小程序中需要使用iconfont,很容易想到了H5的引入方式: ```` @font-f ...