2014-02-11 59 views
0

一個特定的動作我怎麼可以創建在ActiveAdmin控制器的特定動作的形式?類似於此:形成與ActiveAdmin

= form_for @workbook, :url => {:controller => params[:controller], :action =>  "save_workbook_exercise"} do |f| 
     = f.hidden_field :exercise_type, :value => @user_workbook_exercise.workbook_exercise.exercise_type, :class => "hidden_exercise_type" 
     = f.hidden_field :data, :class => "hidden_svg_data" 
     = f.hidden_field :user_id, value: @user.id 
     = f.hidden_field :workbook_exercise_id, :value => @user_workbook_exercise.workbook_exercise.id, :class => "workbook_exercise_id" 
     = f.submit "Save", :onclick => "saveSVG();", :class => "btn btn-primary", :id => "save_button" 

不包含在「ActiveAdmin」語法中。我沒有用ActiveAdmin非常多,但沒有找到我所需要的文檔中的內容。

+1

看看這個 https://gist.github.com/mikeatlas/5628317 –

+0

哦太好了!謝謝!這不正是我想要的。 – cloudwalker

回答

1

如果表單由處理請求的相同控制器呈現,則可以簡化表單。

樣品簿ActiveAdmin資源:

ActiveAdmin.register Workbook do 
    member_action :save_workbook_exercise, :method => :post do 
    workbook = resource 

    # update workbook using params[:workbook] ... 

    workbook.save! 
    redirect_to :action => :show 
    end 
end 

然後你的表單模板:

= semantic_form_for @workbook, :url => { :action => :save_workbook_exercise } do |f| 
    = f.hidden_field :exercise_type, :value => @user_workbook_exercise.workbook_exercise.exercise_type, :class => "hidden_exercise_type" 
    = f.hidden_field :data, :class => "hidden_svg_data" 
    = f.hidden_field :user_id, value: @user.id 
    = f.hidden_field :workbook_exercise_id, :value => @user_workbook_exercise.workbook_exercise.id, :class => "workbook_exercise_id" 
    = f.actions do 
    = f.action :submit, :label => "Save"