我可以很容易地重定向,但我想在验证失败时渲染编辑页面,所以我将所有验证方法都转移到表单中.我不确定如何使用active_admin呈现编辑操作.
如果我尝试render :action => 'edit'我得到一个模板缺少页面我也试过render active_admin_template('edit.html.arb'),它给了我一个页面内的页面,但没有错误.
有任何想法吗?
member_action :state do
space = Space.find(params[:id])
if space.send(params[:state])
#space.send(params[:state]+"!")
flash[:notice] = "State Changed!"
redirect_to :action => :index
else
#render :action => 'edit'
#render active_admin_template('edit.html.arb')
flash[:error] = "#{space.errors}"
redirect_to :action => :edit
end
end
Run Code Online (Sandbox Code Playgroud) validation ruby-on-rails renderaction ruby-on-rails-3 activeadmin
我有这些联想:
class Course < ActiveRecord::Base
has_many :signup
has_many :user, :through => :signup
accepts_nested_attributes_for :signup
end
class User < ActiveRecord::Base
has_many :signup
has_many :course, :through => :signup
accepts_nested_attributes_for :signup
end
class Signup < ActiveRecord::Base
belongs_to :course
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
现在,我想为"注册"自定义ActiveAdmin表单,因此它显示了课程的标题和用户的名称作为选择而不是文本字段.
默认表单已经这样做,但是我需要进一步自定义表单,我无法重现默认表单.
后RAILS_ENV=production bundle exec rake assets:precompile的下拉成为开发环境反应迟钝.点击按钮没有任何反应.然而,从public/assets开始工作中删除一切.它也适用于生产模式(rails s -e production)
该应用程序使用twitter bootstrap和主动管理员.看起来有些事情变得矛盾了.
请注意,它在Heroku上的分段工作正常
这是生成的html的快照
<li id="organization-selector" class="dropdown">
<a href="/" data-toggle="dropdown" data-target="#organization-selector" class="dropdown-toggle">
RedKivi
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>
<a href="/organizations/1">RedKivi</a>
</li>
<li>
<a href="/organizations/2">BoTree</a>
</li>
<li class="divider"></li>
<li>
<a href="/organizations/new">New organization</a>
</li>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
应用程序/资产/样式表/ application.css.scss
...
....
*= require_self
*= require jquery.ui.slider
*= require_tree .
Run Code Online (Sandbox Code Playgroud)
应用程序/资产/ JavaScript的/ application.js中
//= require jquery
//= require jquery_ujs
//= require …Run Code Online (Sandbox Code Playgroud) jquery ruby-on-rails ruby-on-rails-3 activeadmin twitter-bootstrap
这是类别模型.类别可以属于另一个类别.
class Category < ActiveRecord::Base
attr_accessible :title, :parent_id
has_and_belongs_to_many :products, :join_table => :products_categories
belongs_to :parent, :foreign_key => "parent_id", :class_name => "Category"
has_many :categories, :foreign_key => "parent_id", :class_name => "Category"
end
Run Code Online (Sandbox Code Playgroud)
这是产品型号:
class Product < ActiveRecord::Base
attr_accessible :comment, location_id, :category_ids
has_and_belongs_to_many :categories, :join_table => :products_categories
belongs_to :location
end
Run Code Online (Sandbox Code Playgroud)
在产品的Active Admin表单中,我希望根据其parent_id对复选框进行分层排序,例如
以下是我的表格:
ActiveAdmin.register Product do
form do |f|
f.inputs "Product" do
f.input :comment
f.input :categories, :as => :check_boxes
f.input :location
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
目前,表单会拉入复选框并正确保存数据,但我不知道从哪里开始对它们进行分组.我查看了文档,但看不到任何明显的东西.
我正在使用active_admin,我在Rails 3应用程序中的应用程序中有一个目录管理员,其中包含模型和页面的声明.偶尔我也有一个类,当该类有一个常量时,像这样:
class Foo
BAR = "bar"
end
Run Code Online (Sandbox Code Playgroud)
然后,我在每个必须重新加载我的Rails应用程序中的代码的请求中收到此警告:
/Users/pupeno/helloworld/app/admin/billing.rb:12: warning: already initialized constant BAR
Run Code Online (Sandbox Code Playgroud)
有什么想法以及如何避免这些警告?
我想在ActiveAdmin控制器中添加before_action过滤器.
我可以这样做:
before_action :set_product, only: [:show, :edit, :update, :destroy]
private
def set_product
@product = Product.find_by_name(params[:name])
end
Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails ruby-on-rails-3 activeadmin ruby-on-rails-4
我已将我的应用翻译成另一种语言.我创建了ru.yml文件,其中包含视图中所需的所有翻译.在我进入管理路径之前,一切正常.我使用Active Admin,我遇到以下错误:
I18n :: Admin :: Pages #index中的MissingTranslationData
翻译缺失:ru.time.formats.long
insert_tag renderer_for(:index)
怎么解决?我对这两种方式感兴趣:如何翻译Active Admin以及如果我想用英语保存它并且只是修复错误消息该怎么办.
我的User模型可以创建一个Employer或一个Jobseeker,具体取决于布尔Employer属性是否为真.
我想要做的是Employer为Jobseeker单独的范围设置单独的页面,而不仅仅是单独的范围.页面上将有完全不同的表格.
非常感谢!
我正在尝试通过产品表单更新product_suppliers.该表单显示供应商表中的所有供应商,但不更新连接表.不确定错误在哪里.索引和节目显示正确的详细信息,但编辑不更新连接表.开始在这个圈子四处走动.
更新:将表格更改为下面让我接近.但仍然没有更新连接表.但是,如果我手动将行添加到连接表,则删除按预期工作.它们显示并可以删除.保存会将新的product_id添加到行中,而不是关联的supply_company_id值.我认为它是一个属性问题,但我无法看到它.
应用程序/模型/ product.rb
class Product < ActiveRecord::Base
### shortned for clarity
has_many :product_suppliers, :foreign_key => 'product_id'
has_many :supply_companies, :through => :product_suppliers
accepts_nested_attributes_for :product_suppliers, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ supply_company.rb
class SupplyCompany < ActiveRecord::Base
has_many :products, :through => :product_suppliers
has_many :product_suppliers, :foreign_key => 'supply_company_id'
end
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ product_supplier.rb
class ProductSupplier < ActiveRecord::Base
belongs_to :product
belongs_to :supply_company
accepts_nested_attributes_for :product
accepts_nested_attributes_for :supply_company
end
Run Code Online (Sandbox Code Playgroud)
/app/admin/product.rb
ActiveAdmin.register Product do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
permit_params :id, :product_name, :product_description, :product_type_id, :product_category_id, :product_colour_id, …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加ActiveAdmin::Comment到我的Member编辑中.我已经能够通过添加ARB和部分来做到这一点
#_comments.html.arb
active_admin_comments_for(resource)
Run Code Online (Sandbox Code Playgroud)
这显示正常,但当我输入文本然后按添加注释按钮,实际上没有添加注释,它只是返回到显示屏幕.
我想要做的是在那里得到评论,但没有添加评论按钮.我想按Update Member按钮添加评论.这样,对成员所做的任何更改都将与注释一起保存.
有没有办法让它添加Update Member按钮添加注释?
编辑:
我也试过在我的模型中添加一个关系
#model
has_many :comments, as: :resource, dependent: :destroy, class_name: 'ActiveAdmin::Comment'
accepts_nested_attributes_for :comments, reject_if: :reject_comment
# members.rb - form
f.inputs "Add A Comment" do
f.semantic_fields_for :comments, ActiveAdmin::Comment.new do |c|
c.inputs :class => "" do
c.input :resource_id, :input_html => { :value => "1" }, as: :hidden
c.input :resource_type, :input_html => { :value => "Member" }, as: :hidden
c.input :namespace, :input_html => { :value => :admin …Run Code Online (Sandbox Code Playgroud)