Skip to content

Commit

Permalink
class_eval is faster than define_method.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Dec 15, 2008
1 parent b4814b1 commit 4dfa2b8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/controllers/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ def index
end

[:show, :new, :edit, :remove].each do |action|
define_method action do
response_for :singular
end
class_eval %{
def #{action}
response_for :singular
end
}, __FILE__, __LINE__
end

[:create, :update].each do |action|
define_method action do
model.update_attributes!(params[model_symbol])
announce_saved
response_for action
end
class_eval %{
def #{action}
model.update_attributes!(params[model_symbol])
announce_saved
response_for :#{action}
end
}, __FILE__, __LINE__
end

def destroy
Expand Down

0 comments on commit 4dfa2b8

Please sign in to comment.