Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Created November 13, 2009 13:51
Show Gist options
  • Save mrchrisadams/233841 to your computer and use it in GitHub Desktop.
Save mrchrisadams/233841 to your computer and use it in GitHub Desktop.
<%# this partial here is called from within a partial itself %>
<% items.each do |item| %>
<li>
<%= image_tag(item.user.avatar(:nag_tag), :class => "avatar") %>
<div class="activity <%= item.type.to_s.downcase %> bubble">
<%= image_tag('bg/speech_bubble_corner.png', :class => "speech_bubble") %>
<%# debugger %>
<%# this is where I'm getting nil returned when I call both normlised_title and normalised_path in the link_to method %>
<p><%= link_to truncate(h(normalised_title(item)), :length => 60), normalised_path(item) %></p>
<div class="item_icon_<%= item.class.to_s.downcase %> item_icon"></div>
<div class="bottom"></div>
</div>
</li>
<% end %>
## this returns a useful path for the link_to helper
def commentable_path(comment)
case comment.commentable
when Suggestion
thought_path(comment.commentable.thought, :anchor => dom_id(comment))
when Action
action_path(comment.commentable, :anchor => dom_id(comment))
when Thought
thought_path(comment.commentable, :anchor => dom_id(comment))
when Feedback
feedback_path(comment.commentable, :anchor => dom_id(comment))
when Story
thought_action_path(comment.commentable.thought, comment.commentable, :anchor => dom_id(comment))
end
end
## these both return nil but they seem to use the same structure
# this method is used on on the main shared/items partial, for give the correct title
# I'm calling from within a partial
def normalised_title(item)
case item.type
when Action
truncate(h(item.title), :length => 60)
when Comment
truncate(h(strip_tags(item.comment)))
when Feedback
truncate(h(item.title), :length => 60)
when Intent
truncate(h(item.action.title), :length => 60)
when Thought
truncate(h(item.title), :length => 60)
when Suggestion
truncate(h(item.title), :length => 60)
when Story
truncate(h(item.story), :length => 60)
end
end
def normalised_path(item)
case item.type
when Action
suggestion_path(item.suggestion, :anchor => "action_#{item.id}")
when Comment
commentable_path(item)
when Feedback
item
when Intent
suggestion_action_path(item.action.suggestion, item.action)
when Thought
item
when Suggestion
item
when Story
suggestion_action_path(item.action.suggestion, item.action)
end
end
## Calling the method manually for a Thought works here already
(rdb:426) item
#<Thought id: 81, user_id: 3, thought_type: nil, locality: "1", title: "Write the problem title here", description: "Explain the problem here", created_at: "2009-11-11 14:58:26", updated_at: "2009-11-11 14:58:26", hotness: nil, flagged_as_inappropriate: false, removed_as_inappropriate: false, attachment_file_name: nil, attachment_content_type: nil, attachment_file_size: nil>
(rdb:426) link_to truncate(h(item.title), :length => 60), item
"<a href=\"/problems/81\">Write the problem title here</a>"
(rdb:426) normalised_title(item)
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment