我试图以某种方式显示line items了order在active_admin order show page,没有运气..
这里是模型之间的关系:
order.rb
class Order < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
# ...
validates :name, :address, :email, :presence => true
validates :pay_type, :inclusion => PAYMENT_TYPES
end
Run Code Online (Sandbox Code Playgroud)
line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
belongs_to :cart
def total_price
product.price * quantity
end
end
Run Code Online (Sandbox Code Playgroud)
active_admin order.rb
ActiveAdmin.register Order do
show do
attributes_table :name, :email, :address, :pay_type, :created_at, :updated_at
end
end
Run Code Online (Sandbox Code Playgroud)
active_admin line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product …Run Code Online (Sandbox Code Playgroud) 有没有简单的方法可以从默认的ISO格式(yyyy-mm-dd)更改ActiveAdmin日期过滤器显示格式?
当您编辑has_one个人资料的用户时,活动管理员删除该个人资料并重新创建它,这使得通过回形针删除头像图像
如何让活动管理员只更新嵌套表单而不删除并重新创建它.
这是我的ActiveAdmin:用户代码
ActiveAdmin.register User do
menu :priority => 2
## Controller
controller do
def update
if params[:user][:password].blank?
params[:user].delete("password")
params[:user].delete("password_confirmation")
end
if params[:user][:profile_attributes][:avatar].blank?
params[:user][:profile_attributes].delete("avatar")
end
super
end
def permitted_params
params.permit user: [:username, :email, :password, :password_confirmation, :approved, role_ids: [], profile_attributes: [:first_name, :last_name, :date_of_birth, :avatar]]
end
end
#Scopes
scope :all, default: true
scope :admins
scope :editors
scope :members
## Filters
filter :username
filter :email
## Index
index do
column :id
column :first_name do |user|
user.profile.first_name unless user.profile.nil?
end
column :last_name do |user| …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序需要三个用户类型(用户,代理,管理员)登录并需要不同的设计模块.
User AgentAdmin AdminUser
confirmable Yes Yes No
lockable Yes Yes No
timeoutable No Yes Yes
Omniauthable Yes No No
database_authenticatable Yes Yes Yes
recoverable Yes Yes No
rememberable Yes Yes No
trackable Yes Yes Yes
validatable Yes Yes Yes
Run Code Online (Sandbox Code Playgroud)
此外,这些用户可以根据其类型添加其他列.所以,我想根据类型创建不同的表.
根据我的要求,我决定来处理AgentAdmin,并AdminUser与ActiveAdmin有不同的命名空间(联系管理员AdminUser,代理AgentAdmin).我已经配置authentication_method,current_user_method并logout_link_path为这两个命名空间,如下.
config.load_paths = [File.join(Rails.root,'app','admin'), File.join(Rails.root,'app','agent')]
config.namespace :admin do |admin|
admin.authentication_method = :authenticate_admin_user!
admin.current_user_method = :current_admin_user
admin.logout_link_path = :destroy_admin_user_session_path
end
config.namespace :agent do |agent| …Run Code Online (Sandbox Code Playgroud) 更新ActiveAdmin后出现以下错误:
上 http://0.0.0.0:3000/admin
Routing Error
uninitialized constant Admin::DashboardController
Run Code Online (Sandbox Code Playgroud)
我试过在ActiveActive路由之前移动自定义根目录并设计路由。
我的路线:
MyApp::Application.routes.draw do
root :to => "download#index"
devise_for :users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
Run Code Online (Sandbox Code Playgroud)
我的耙路:
root / download#index
new_user_session GET /admin/login(.:format) active_admin/devise/sessions#new
user_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_user_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PUT /admin/password(.:format) active_admin/devise/passwords#update
root / dashboard#index
admin_root /admin(.:format) admin/dashboard#index
Run Code Online (Sandbox Code Playgroud)
我已经解决了几乎所有的堆叠问题,对于此问题的任何帮助将不胜感激!
解:
解决方法:
触摸app / admin / dashboard.rb
并从以下代码中添加了代码:
我有以下代码:
div class: item.ui_type do
link_to image_tag(item.image.image_public_url), item.target)
link_to item.label, item.target
end
Run Code Online (Sandbox Code Playgroud)
基本上,我想要一个具有2个链接的div。但是,仅渲染最后一个元素,大概是因为在体内渲染的是块的返回值。
我知道我可以将它们声明为数组并加入它们,但是然后我需要调用html_safe。当您实际上不信任收到的输入时,我正在尝试找到一种方法来执行此操作。
这似乎应该是一件非常简单的事情,但是我在任何地方都找不到。
有指针吗?
我想定制以下内容
我想使用Devise登录具有相同用户模型的常规非管理员用户.所以我使用角色id作为另一个属性,一切正常.挑战在于我必须为前端用户创建自定义登录页面,注册页面和其他相关页面.当前路由文件是:
Rails.application.routes.draw do
devise_for :users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
end
Run Code Online (Sandbox Code Playgroud)
由于我想生成新的登录表单并想要覆盖控制器,我添加了devise_for:users但它给了我一个定义的错误路由.我怎么能解决冲突?
此外,以下是有效的管理员设置:
config.authentication_method = :authenticate_user!
config.current_user_method = :current_user
Run Code Online (Sandbox Code Playgroud)
我想自定义登录页面并注册页面控制器,因为我必须在注册表单中添加一些内容.
我可能会遗漏一些基本的东西,但我似乎无法让ActiveAdmin使用可排序的has_many通过关系,能够创建新记录.
所以给出以下模型
class User < ActiveRecord::Base
has_many :user_videos
has_many :videos, through: :user_videos
accepts_nested_attributes_for :user_videos
accepts_nested_attributes_for :videos
...
end
class UserVideo < ActiveRecord::Base
belongs_to :user
belongs_to :video
accepts_nested_attributes_for :video
end
class Video < ActiveRecord::Base
has_many :user_videos
has_many :users, through: :user_videos
...
end
Run Code Online (Sandbox Code Playgroud)
(我承认我accepts_nested_attributes_for在某种程度上可能会有所作为)
Active Admin设置就像这样(当然是WIP):
f.inputs "User" do
f.has_many :user_videos, heading: 'Videos', sortable: :order, allow_destroy: true, new_record: 'New Record' do |v|
v.inputs for: :video do |video|
video.input :video_url
end
end
f.has_many :videos, heading: 'Videos', new_record: 'New Video' do |v| …Run Code Online (Sandbox Code Playgroud) 我希望在管理页面上为用户显示一个过滤器,以显示同时具有Subject_A和Subject_B的用户。
使用下面的代码行,我已经能够筛选出具有Subject_A或Subject_B或两者兼有的用户。
filter :universities, as: :select, multiple: true
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以使用Active Admin创建过滤器,以过滤仅具有Subject_A 和 Subject_B的用户?
activeadmin ×10
ruby ×3
arbre ×1
date ×1
devise ×1
forms ×1
formtastic ×1
nested ×1
paperclip ×1
postgresql ×1