[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Help needed to DRY helpers and proper MVC with Ruby

Becca Girl

7/27/2007 7:05:00 PM

Hello.

I've got working code, but I don't think that it's done properly so any
help to make this more efficient and most of all, correct, would be so
very appreciated.

In my users_helper.rb file

def generate_sub_nav
if session[:user]
sub_nav_menu = []
user = User.find(session[:user])
for role in user.roles
for right in role.rights
if right.on_menu
sub_nav_menu << right.id
end
end # for right
end # for role
end # if
sub_nav_menu.sort!
end # def


In my application_helper.rb file for the layout and display

def show_sub_nav(rights)
html_out = '<table><tr><td>'

for right in rights
right_array = Right.find(:all, :conditions => ["id = ?", right])
for menu in right_array
html_out << link_to_unless_current (menu.name,
:controller => menu.controller, :action => menu.action)
end
end #for right in rights

html_out << '</td></tr></table>'
html_out
end



In my controllers (not including the user_controller)

helper :users


There's got to be a better, more Ruby like way to do this.

THANKS!
--
Posted via http://www.ruby-....

2 Answers

suzeeq

9/6/2012 5:27:00 PM

0

Dano wrote:
> "The Original Crank it Up" wrote in message
> news:34a314c2-0d05-4291-89bf-39355c2bd04d@googlegroups.com...
>
> I dont get it. Unless the pollsters told the Clintons what was Really
> up..
> and it doesn't look good. Frankly I am puzzled. Please help..... I will
> say
> that Brother Clinton had a gorgeous Sun Tan..
>
> =========================================
>
> You don't get what? You DO know that Hillary has a pretty important job
> that she's actually doing don't you? I would not be surprised if you don't.
>
> And why should Bubba NOT have a tan? Is golfing forbidden to even
> ex-presidents now? It is still summer you know.

And he's retired... Gerald Ford had a great tan too, year round.

> Boehner has HIS year round. So does Obama. What's the speaker's excuse?

trotsky

9/6/2012 6:12:00 PM

0

On 9/6/12 12:09 PM, Barb May wrote:
> Dano wrote:
>> "The Original Crank it Up" wrote in message
>> news:34a314c2-0d05-4291-89bf-39355c2bd04d@googlegroups.com...
>>
>> I dont get it. Unless the pollsters told the Clintons what was
>> Really up..
>> and it doesn't look good. Frankly I am puzzled. Please help..... I
>> will say
>> that Brother Clinton had a gorgeous Sun Tan..
>>
>> =========================================
>>
>> You don't get what? You DO know that Hillary has a pretty important
>> job that she's actually doing don't you? I would not be surprised if
>> you don't.
>> And why should Bubba NOT have a tan? Is golfing forbidden to even
>> ex-presidents now? It is still summer you know.
>>
>> Boehner has HIS year round. So does Obama. What's the speaker's
>> excuse?
>
> Boehner hired Snookie as his tanning consultant.


He was orange with envy.