5
votes
3answers
181 views

Setting bgcolor in Ruby. What's the proper way to do it?

<p style="background-color:#<%= debate.bg_color %>;" > be_color is a method of Debate that returns a string like 45FFFF. Although it does what I want, this seems like a tremendously bad ...
5
votes
1answer
219 views

Refactor Helper methods

I have two helper methods that return li for view with the li for current view having id as selected. def get_li(a) li = "<li" li += ' id=selected' if (a[:controller] == params[:controller] ...
3
votes
1answer
133 views

Nasty Age Printing Method

I have this ugly age printing method. Can you do better? def age(birth_date) today = Date.today years = today.year - birth_date.year months = today.month - birth_date.month (months -1) if ...
3
votes
1answer
159 views

ruby code case when not so dry

Ruby code below seems to be not so dry. Can you please help me reduce the code. self.value = case self.type when 'fast' Increment.first.max_hours * Incrementor.first.fast_completion_day when ...
2
votes
1answer
208 views

Rails 3: How can I improve this ActiveRecord count

Here I retrieve a collection of causes from the database. Along with the information from each cause, I want to send the number of users in each cause. This way works, but if experience has told me ...
2
votes
2answers
365 views

Is that good practise to add a flash message to redirect in a single command in rails

I read this scrap and it says that i can add a flash message to redirect in a single command in rails. But when i tried in my rails 2.3.4 application it doesn't work. This is my working code def ...