主动管理定制

发布于 2024-12-18 16:49:50 字数 167 浏览 1 评论 0原文

我有一个带有字段状态的 Event 模型,它是字符串,因此它显示为 text_field。但我有一个可能状态的列表,我想将其显示为选择框。此外,当我选择活动的取消状态时,它应该询问我取消原因。我无法为此找到好的教程。

I have an Event model with field status, which is string so it appears as a text_field. But I have a list of possible statuses and I want to display it as a select box. Also, when I select cancel status for a event it should ask me for the cancellation reason. I am not able to find good tutorial for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热鲨 2024-12-25 16:49:50

以下是几乎所有自定义的示例:)

ActiveAdmin.register Event do
  #Menu display index
  menu :priority => 1

  #Scopes
  scope :all
  scope :pending
  scope :approved
  scope :rejected
  scope :cancelled
  scope :featured

  #Filters  
  filter :city
  filter :user, :content_columns => :first_name
  filter :name
  filter :featured
  filter :location
  filter :details
  filter :start_datetime
  filter :end_datetime

  # New/Edit forms  
  form do |f|
    f.inputs do
      f.input :status, :label => "Event Status", :as => :select, :collection => Event::EVENT_STATUSES
      # Conditional show/hide using js
      cancel_reason_style = f.object.cancelled? ? "display:block" : "display:none"
      reject_reason_style = f.object.rejected? ? "display:block" : "display:none"
      f.input :reject_reason, :wrapper_html => {:style => reject_reason_style}, :hint => "Required if status event rejected"
      f.input :cancel_reason, :wrapper_html => {:style => cancel_reason_style}, :hint => "Required if status event rejected"
      f.input :city, :label => "Event Status"
      f.input :name, :label => "Name"
      f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:medium))
      f.input :details, :input_html => { :class => 'autogrow', :rows => 5, :cols => 30, :maxlength => 10  }
      f.input :start_datetime
      f.input :end_datetime
      f.input :location, :input_html => { :class => 'autogrow', :rows => 5, :cols => 30, :maxlength => 10  }
      f.input :gmap_lattitude
      f.input :gmap_logitude
      f.input :email
      f.input :mobile
      f.input :website
    end
    f.buttons
  end

  index do
    column :name
    column :user
    column :city
    column :status
    column :start_datetime
#    column :end_datetime
    column :email
    default_actions
  end

  show do |event|
    attributes_table do
      row :name
      row :details
      row :user
      row :city
      row :status do event.status.titleize end
      # has_many :through
      row :themes do
        event.themes.collect{|t| t.name}.join(', ')
      end
      row :event_type do
        event.event_types.collect{|t| t.name}.join(', ')
      end
      row :start_datetime
      row :end_datetime
      row :location
      row :gmap_lattitude
      row :gmap_logitude
      row :email
      row :mobile
      row :created_at
      row :updated_at

    end
    active_admin_comments
  end

end

编辑
有一些可用的主题

https://github.com/vigetlabs/active_material

https://github.com/activeadmin-plugins/active_admin_theme

https://github.com/paladini/activeadmin-themes

Following is the example almost all customizations :)

ActiveAdmin.register Event do
  #Menu display index
  menu :priority => 1

  #Scopes
  scope :all
  scope :pending
  scope :approved
  scope :rejected
  scope :cancelled
  scope :featured

  #Filters  
  filter :city
  filter :user, :content_columns => :first_name
  filter :name
  filter :featured
  filter :location
  filter :details
  filter :start_datetime
  filter :end_datetime

  # New/Edit forms  
  form do |f|
    f.inputs do
      f.input :status, :label => "Event Status", :as => :select, :collection => Event::EVENT_STATUSES
      # Conditional show/hide using js
      cancel_reason_style = f.object.cancelled? ? "display:block" : "display:none"
      reject_reason_style = f.object.rejected? ? "display:block" : "display:none"
      f.input :reject_reason, :wrapper_html => {:style => reject_reason_style}, :hint => "Required if status event rejected"
      f.input :cancel_reason, :wrapper_html => {:style => cancel_reason_style}, :hint => "Required if status event rejected"
      f.input :city, :label => "Event Status"
      f.input :name, :label => "Name"
      f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:medium))
      f.input :details, :input_html => { :class => 'autogrow', :rows => 5, :cols => 30, :maxlength => 10  }
      f.input :start_datetime
      f.input :end_datetime
      f.input :location, :input_html => { :class => 'autogrow', :rows => 5, :cols => 30, :maxlength => 10  }
      f.input :gmap_lattitude
      f.input :gmap_logitude
      f.input :email
      f.input :mobile
      f.input :website
    end
    f.buttons
  end

  index do
    column :name
    column :user
    column :city
    column :status
    column :start_datetime
#    column :end_datetime
    column :email
    default_actions
  end

  show do |event|
    attributes_table do
      row :name
      row :details
      row :user
      row :city
      row :status do event.status.titleize end
      # has_many :through
      row :themes do
        event.themes.collect{|t| t.name}.join(', ')
      end
      row :event_type do
        event.event_types.collect{|t| t.name}.join(', ')
      end
      row :start_datetime
      row :end_datetime
      row :location
      row :gmap_lattitude
      row :gmap_logitude
      row :email
      row :mobile
      row :created_at
      row :updated_at

    end
    active_admin_comments
  end

end

EDIT
There are a few themes available

https://github.com/vigetlabs/active_material

https://github.com/activeadmin-plugins/active_admin_theme

https://github.com/paladini/activeadmin-themes

想念有你 2024-12-25 16:49:50

ActiveAdmin 使用 Formtastic 生成表单,因此 Formtastic 的文档应该可以回答您的问题。

您可以使用以下代码获得选择而不是文本字段:

form do |f|
  f.status, :as => :select, :collection => STATUSES #whatever collection you want to display
end

选择“取消”时触发事件应该使用 javascript 解决。

ActiveAdmin uses Formtastic for form generation, so Formtastic's documentation should answer your questions.

You can get a select instead of a textfield with the following code:

form do |f|
  f.status, :as => :select, :collection => STATUSES #whatever collection you want to display
end

Triggering an event when selecting "cancelled" should be solved with javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文