Block call in Ruby on Rails
Posted
by Mattias
on Stack Overflow
See other posts from Stack Overflow
or by Mattias
Published on 2010-06-16T10:35:41Z
Indexed on
2010/06/16
11:52 UTC
Read the original article
Hit count: 143
Hi,
I'm trying to clean up my code and get rid of a lot of ugly hashes. In my views I define several actions like this:
@actions = {
:interest => {'Show interest', link_to(..), :disabled => true},
:follow => {'Follow this case', link_to(..)}
...
}
As these hashes grow, the maintainability decreases. I want to convert the above format to something like:
actions do
item :interest, 'Show interest', link_to(..), :disabled => true
item :follow, 'Follow', link_to(..)
...
end
How do I structure my helper methods to allow this? Preferably the 'item'-method should only be available in the 'actions' block and not in the global scope.
Thanks!
© Stack Overflow or respective owner