module SomeHelper
def percent_bar(percent, count, container_size=300)
pixel_width = (percent / 100.0 * container_size).to_i
render(:partial => 'shared/member_progress',
:locals => {
:percent => percent.round,
:pixel_width => pixel_width,
:count => count
})
end
end
There's really no good reason for the help to render the view. Having this render in the helper is masking that there is html being rendered. I suggest something like:
module SomeHelper
def pixel_width_for(percent, container_size = 300)
(percent / 100.0 * container_size).to_i
end
end
render 'shared/member_progress', :percent => social_deal.thumbs_up_percent.round,
:pixel_width => pixel_width_for(social_deal.thumbs_up_percent),
:count => social_deal.thumbs_up_count
Now I understand there's more effort to make that happen, so if it's an issue, clean up the partial to take the simplest variables, like so:
render 'shared/new_progress', :percent => social_deal.thumbs_up_percent,
:count => social_deal.thumbs_up_count
// file 'shared/_new_progress'*
<span class="percent">
<span class="progress" style="width: <%= percent %>%"><%= percent %>%</span>
<span class="vote-count"><%= count > votes</span>
</span>
Keeping the markup in the views make more sense to me.
- I know I changed from fixed pixels to a percent, seemed simpler.