Skip to content

Commit

Permalink
Added fav and unfav.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 10, 2009
1 parent 5189c6b commit d5f286b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ def create
flash[:notice] = "Got it! Tweet ##{tweet.id} created."
return_to_or root_url
end

def fav
flash[:notice] = "Tweet fav'd. May not show up right away due to API latency."
current_user.client.favorite_create(params[:id])
return_to_or root_url
end

def unfav
flash[:notice] = "Tweet unfav'd. May not show up right away due to API latency."
current_user.client.favorite_destroy(params[:id])
return_to_or root_url
end
end
7 changes: 7 additions & 0 deletions app/views/statuses/_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

<p class="actions">
<%= link_to image_tag('chat.gif'), status_url(:id => status.in_reply_to_status_id), :class => 'icon' unless status.in_reply_to_status_id.blank? %>
<%- if status.favorited -%>
<%= link_to image_tag('star_on.gif'), unfav_status_url(:id => status.id, :return_to => request.request_uri), :class => 'icon', :method => :post %>
<%- else -%>
<%= link_to image_tag('star.gif'), fav_status_url(:id => status.id, :return_to => request.request_uri), :class => 'icon', :method => :post %>
<%- end -%>
<%= link_to image_tag('mail.gif'), '#', :class => 'dm icon', :rel => h(user.screen_name), :title => "Direct Message #{h user.screen_name}" %>
<%= link_to image_tag('comment.gif'), '#', :class => 'reply icon', :rel => h("#{user.screen_name}:#{status.id}"), :title => "Reply to #{h user.screen_name}" %>
</p>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'statuses'

map.resources :statuses, :collection => {:mentions => :get, :favorites => :get}
map.resources :statuses, :collection => {:mentions => :get, :favorites => :get},
:member => {:fav => :post, :unfav => :post}
map.resources :direct_messages
map.resources :users, :has_one => [:password, :confirmation]
map.resources :passwords
Expand Down

0 comments on commit d5f286b

Please sign in to comment.