diff options
author | Marius Mathiesen <marius@shortcut.no> | 2009-11-26 15:42:24 +0100 |
---|---|---|
committer | Marius Mathiesen <marius@shortcut.no> | 2009-12-03 14:18:58 +0100 |
commit | c753d1dbaa667dc9382c28f5942d95f46a1b765f (patch) | |
tree | 8559c60b81806d4861d1ca3f5e6254cd4e4df1e8 /app | |
parent | e45da1cce6d9e71605c29c9c0672203f3fec0824 (diff) | |
download | gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.zip gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.tar.gz gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.tar.bz2 |
Hook into the create/delete actions for watching with some Ajax goodness
- Add a custom attr to the a tags
- Replace the obtrusive Rails actions with some homebrew
- Favorites#{create,destroy} now supplies a Location header intercepted by javascript
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/favorites_controller.rb | 10 | ||||
-rw-r--r-- | app/views/repositories/show.html.erb | 5 |
2 files changed, 9 insertions, 6 deletions
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 1596a3e..fff8e84 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -26,26 +26,28 @@ class FavoritesController < ApplicationController before_filter :find_watchable, :only => [:create] def create - @favorite = current_user.favorites.create(:watchable => @watchable) + @favorite = current_user.favorites.create!(:watchable => @watchable) respond_to do |wants| wants.html { flash[:notice] = "You are now watching this #{@watchable.class.name.downcase}" redirect_to repo_owner_path(@watchable, [@watchable.project, @watchable]) } - wants.js {render :status => :created, :nothing => true} + wants.js {render :status => :created, :nothing => true, + :location => polymorphic_path(@favorite)} end end def destroy @favorite = current_user.favorites.find(params[:id]) @favorite.destroy + watchable = @favorite.watchable respond_to do |wants| wants.html { - watchable = @favorite.watchable flash[:notice] = "You no longer watch this #{watchable.class.name.downcase}" redirect_to repo_owner_path(watchable, [watchable.project, watchable]) } - wants.js {head :ok} + wants.js {head :ok, :location => url_for(:action => "create", :watchable_id => watchable.id, + :watchable_type => watchable.class.name, :only_path => true)} end end diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 0ef2093..15eb3b8 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -77,10 +77,11 @@ <% if logged_in? -%> <li class="watch"> <% if favorite = current_user.favorites.detect{|f| f.watchable == @repository} -%> - <%= link_to("Stop watching this repository", favorite_path(favorite), :method => "delete") -%> + <%= link_to("Stop watching this repository", favorite_path(favorite), :method => "delete", :"data-request-method" => "delete") -%> <% else -%> <%= link_to("Start watching this repository", - favorites_path(:watchable_id => @repository.id, :watchable_type => @repository.class.name), :method => :post) -%> + favorites_path(:watchable_id => @repository.id, :watchable_type => @repository.class.name), + :method => :post, :"data-request-method" => "post") -%> <% end -%> </li> <% end -%> |