Use static helper for aspect links

This commit is contained in:
Raphael 2010-11-30 12:23:43 -08:00
parent b84d2bcc56
commit 49e8347aa3
3 changed files with 36 additions and 7 deletions

View file

@ -9,6 +9,38 @@ module ApplicationHelper
false false
end end
def aspects_with_post aspects, post
aspects.select do |a|
post.aspect_ids.include?(a.id)
end
end
def aspects_without_post aspects, post
aspects.reject do |a|
post.aspect_ids.include?(a.id)
end
end
def aspect_links aspects, opts={}
str = ""
aspects.each do |a|
str << aspect_li(a, opts)
end
str.html_safe
end
def aspect_li aspect, opts= {}
param_string = ""
if opts.size > 0
param_string << '?'
opts.each_pair do |k,v|
param_string << "#{k}=#{v}"
end
end
"<li>
<a href='/aspects/#{aspect.id}#{param_string}'>
#{aspect.name}
</a>
</li>".html_safe
end
def current_aspect?(aspect) def current_aspect?(aspect)
!@aspect.nil? && !@aspect.is_a?(Symbol) && @aspect.id == aspect.id !@aspect.nil? && !@aspect.is_a?(Symbol) && @aspect.id == aspect.id
end end

View file

@ -7,6 +7,5 @@
= link_to t('.reshare'), "#" = link_to t('.reshare'), "#"
%ul.reshare_box %ul.reshare_box
- for aspect in aspects =aspect_links(aspects, :prefill => post.message)
%li.aspect_to_share= link_to aspect, :controller => "aspects", :action => "show", :id => aspect.id, :prefill => post.message

View file

@ -17,14 +17,12 @@
- if post.public? - if post.public?
%li= t('the_world') %li= t('the_world')
- else - else
- for aspect in aspects.select{|a| post.aspect_ids.include?(a.id)} =aspect_links(aspects_with_post(aspects, post))
%li
%a{:href => "/aspects/#{aspect.id}"}=aspect.name
.right .right
- reshare_aspects = aspects.reject{|a| post.aspect_ids.include?(a.id)} - reshare_aspects = aspects_without_post(aspects, post)
- unless reshare_aspects.empty? - unless reshare_aspects.empty?
= render 'shared/reshare', :current_user => current_user, :aspects => aspects, :post => post = render 'shared/reshare', :current_user => current_user, :aspects => reshare_aspects, :post => post
= link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete"
= render 'status_messages/status_message', :post => post, :photos => post.photos = render 'status_messages/status_message', :post => post, :photos => post.photos