2013-08-26 43 views
0

在插件開發中需要一些幫助。 我已經在用戶/編輯表單視圖中創建了鉤子,添加了ballance_amount以形成並具有"ballance_amount"=>"1"Redmine:擴展插件中的控制器動作

如何擴展用戶控制器中的默認更新操作?

base.class_eval do我已經添加了alias_method_chain :update, :ballanceInstanceMethods

def update_with_ballance 
    ballance.amount = params[:user][:ballance_amount].to_f #I have ballance association 
end 

而得到這樣的:

NameError (undefined local variable or method `params' for #<User:0x007f972e9379d0>): 
app/controllers/users_controller.rb:144:in `update' 

我怎樣才能獲取PARAMS?

回答

0

您應該能夠在Redmine本身中使用批量分配代碼。如果balance_amount被認爲是safe_attributeLine 135 in the UsersController應該爲您的分機提供一個簡單的入口點。爲了實現這一點,添加補丁類似下面的用戶模式:

module RedmineBalancePlugin::UserPatch 
    def self.included(base) 
    base.class_eval do 
     safe_attributes 'balance_amount' 

     include InstanceMethods 
    end 
    end 

    module InstanceMethods 
    # This method is indirectly called when creating or updating a User 
    def balance_amount=(amount) 
     balance.amount = amount 
    end 

    # This could be useful in your view patch, but maybe not 
    def balance_amount 
     balance.amount 
    end 
    end 
end 

User.send(:include, RedmineBalancePlugin::UserPatch) 

如果這個例子沒有幫助,這將是有幫助的,如果你能提供更多的代碼片段 - 例如UsersController的完整補丁,以便更容易地重現和分析問題。