Class_eval problem

6 views
Skip to first unread message

mukesh singh

unread,
Jun 21, 2011, 7:41:54 AM6/21/11
to rubyonra...@googlegroups.com
class AssigneesController < ApplicationController

 def assignees   
  @assinees = Assignee.find(:all, :select => "#{params[:assignee_clean_by]}, id").uniq_by(&"#{params[:assignee_clean_by]}".to_sym)    
  Assignee.class_eval %Q{
                def assignee_name
                    self["#{params[:assignee_clean_by]}"]
                end
           }
  end  

 def do_assignee_cleaning
      Assignee.find(1).assignee_name
      redirect_to assignee_cleaning_project_assignees_path(params[:project_id])
  end
end


in assignees.html.erb

@assignees.each do |assignee|
  assignee.assignee_name
end
 
I am able to call assignee_name method on assignee object in assignees.html.erb.
But in do_assignee_cleaning action, i get error undefined method `assignee_name' for #<Assignee:0xc306ac> why?
 

Chirag Singhal

unread,
Jun 21, 2011, 8:01:18 AM6/21/11
to rubyonra...@googlegroups.com
As Colin mentioned on the other thread, you will need to call assignees before you call do_assignee_cleaning, otherwise the assignee_name method wouldn't be defined
Reply all
Reply to author
Forward
0 new messages