ruby on rails 3 - Redmine: extend controller action in plugin -


need in plugin development. i've created hook in user/edit form view, added ballance_amount form , have "ballance_amount"=>"1".

how can extend default update action in user controller?

in base.class_eval do i've added alias_method_chain :update, :ballance in instancemethods:

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

and this:

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

how can fetch params?

you should able make use of mass-assignment code in redmine itself. line 135 in userscontroller should handle provide simple entry point extension, if balance_amount considered safe_attribute. achieve that, add patch following user model:

module redminebalanceplugin::userpatch   def self.included(base)     base.class_eval       safe_attributes 'balance_amount'        include instancemethods     end   end    module instancemethods     # method indirectly called when creating or updating user     def balance_amount=(amount)       balance.amount = amount     end      # useful in view patch, maybe not     def balance_amount       balance.amount     end   end end  user.send(:include, redminebalanceplugin::userpatch) 

if example not help, helpful, if provide more code fragments - e.g. complete patch userscontroller, make easier reproduce , analyse issue.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -