Created
November 13, 2009 13:51
-
-
Save mrchrisadams/233841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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