0
点赞
收藏
分享

微信扫一扫

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post


跟着上文继续走。 Post已经有了,新建Post 的时候结果报错了:

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_自定义

 

链接:​​https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters​​

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_自定义_02

#app\admin\posts.rb
ActiveAdmin.register Post do
permit_params :title, :content, :publisher_id

# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# Uncomment all parameters which should be permitted for assignment
#
# permit_params :title, :content
#
# or
#
# permit_params do
# permitted = [:title, :content]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end

end

然后继续新建:

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_自定义_03

 

盗文章的比较多,我尽量截图来搞了。

 

另外菜单会自动加进去

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_自定义_04

#app\admin\posts.rb
ActiveAdmin.register Post do
menu false
permit_params :title, :content, :publisher_id

# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# Uncomment all parameters which should be permitted for assignment
#
# permit_params :title, :content
#
# or
#
# permit_params do
# permitted = [:title, :content]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end

end

这样的话会隐藏菜单

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_github_05

 

也可以自定义标题

ActiveAdmin.register Post do
menu label: "自己搞的标题",priority: 1
#priority是标题位置,默认是10
permit_params :title, :content, :publisher_id

# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# Uncomment all parameters which should be permitted for assignment
#
# permit_params :title, :content
#
# or
#
# permit_params do
# permitted = [:title, :content]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end

end

Ruby on Rails _使用Active Admin后台模板 三 新增一个 post_自定义_06

 

举报

相关推荐

0 条评论