嗨,大家好 ,
我在我的项目中实现了 rails admin 现在有几件事我目前坚持
我想要一个链接(标记为发布者)在rails admin中我的用户控制器的列表视图中作为ajax链接使用remote => true在rails中完成的事情,然后为它编写相关的jscode和html代码
对于上述自定义操作“ mark_as_publisher ”,我定义了这样的配置设置
在config/rails_admin.rb里面
config.actions do # root actions dashboard # mandatory # collection actions index # mandatory new export history_index bulk_delete # member actions show edit delete history_show show_in_app member :mark_as_publisher end
现在自定义动作的定义看起来像这样
require "rails_admin_mark_as_publisher/engine" module RailsAdminMarkAsPublisher end require 'rails_admin/config/actions' module RailsAdmin module Config module Actions class MarkAsPublihser < Base RailsAdmin::Config::Actions.register(self) register_instance_option :collection do true end register_instance_option :http_methods do [:get,:post] end register_instance_option :route_fragment do 'mark_as_publisher' end register_instance_option :controller do Proc.new do binding.pry if request.get? respond_to do |format| format.html { render @action.template_name} end elsif request.post? redirect_path = nil if @object.update_attributes(:manager => true) flash[:success] = t("admin.flash.successful", :name => @model_config.label, :action => t("admin.actions.mark_as_publisher.done")) redirect_path = index_path else flash[:error] = t("admin.flash.error", :name => @model_config.label, :action => t("admin.actions.mark_as_publisher.done")) redirect_path = back_or_index end end end end end end end end
现在app/view/rails_admin/main/mark_as_publisher.erb中相同定义的视图 看起来像这样
<%= rails_admin_form_for @object, :url => mark_as_publisher_path(:model_name => @abstract_model.to_param, :id => @object.id), :as => @abstract_model.param_key,:method => :post ,:html => { :class => "form-horizontal denser", :data => { :title => "Mark" } } do |form| %>
<%= form.submit "save" %>
<%end%>
mark_as_publisher 的 get 和 post url 确实属于上面的控制器定义,保存上面的表单会导致错误调用
could not find routes for '/user/5/mark_as_publisher' :method => "post"
有没有人知道我错过了什么