Browse files

Fix and improve routes and links.

  • Loading branch information...
1 parent f776013 commit 13310468dfee2cc5096bb790701c6e6b53ecf44d @ashcmd ashcmd committed May 11, 2012
View
9 app/controllers/pastes_controller.rb
@@ -23,7 +23,7 @@ class PastesController < ApplicationController
default_search_scope :pastes
- before_filter :find_project, :authorize
+ before_filter :find_paste_and_project, :authorize
accept_rss_auth :index
@@ -86,12 +86,12 @@ def update
def destroy
@paste.destroy
flash[:notice] = l(:notice_paste_destroyed)
- redirect_to pastes_path(:project_id => @project.id)
+ redirect_to :action => "index", :project_id => params[:project_id]
end
private
- def find_project
+ def find_paste_and_project
if params[:project_id].present?
@project = Project.find(params[:project_id])
@pastes = @project.pastes
@@ -101,10 +101,7 @@ def find_project
if params[:id].present?
@paste = @pastes.find(params[:id])
@project ||= @paste.project
- else
- @projects = Project.visible.has_module(:pastes)
end
- @pastes ||= Paste.for_project(@project || @projects)
rescue ActiveRecord::RecordNotFound
render_404
end
View
17 app/helpers/pastes_helper.rb
@@ -85,23 +85,28 @@ def paste_timestamp(paste)
end
end
+ def url_to_paste(action, paste = nil)
+ { :controller => "pastes", :action => action,
+ :id => paste, :project_id => @project }
+ end
+
def link_to_paste(paste)
link_to paste.title, paste
end
def edit_paste_link(paste, title = l(:button_edit))
- link_to_if_authorized title, { :action => "edit", :id => paste },
+ link_to_if_authorized title, url_to_paste("edit", paste),
:class => "icon icon-edit"
end
def delete_paste_link(paste, title = l(:button_delete))
- link_to_if_authorized title, { :action => "destroy", :id => paste },
+ link_to_if_authorized title, url_to_paste("destroy", paste),
:class => "icon icon-del",
:method => :delete, :confirm => l(:text_paste_delete_confirmation)
end
def download_paste_link(paste, title = l(:button_download))
- link_to title, { :action => "download", :id => paste },
+ link_to title, url_to_paste("download", paste),
:class => "icon icon-save"
end
@@ -112,14 +117,12 @@ def manage_paste_links(paste)
end
def link_to_all_pastes
- link_to l(:label_paste_view_all),
- { :controller => "pastes", :action => "index", :project_id => @project },
+ link_to l(:label_paste_view_all), url_to_paste("index"),
:class => "icon icon-multiple"
end
def link_to_new_paste
- link_to_if_authorized l(:label_paste_new),
- { :controller => "pastes", :action => "new", :project_id => @project },
+ link_to_if_authorized l(:label_paste_new), url_to_paste("new"),
:class => "icon icon-add"
end
end
View
2 app/views/pastes/_sidebar.html.erb
@@ -1,5 +1,5 @@
<% content_for :sidebar do %>
<h3><%=l :label_paste_plural %></h3>
<p><%= link_to_new_paste %></p>
-<p><%= link_to_all_pastes %></p>
+<p><%= link_to_all_pastes if @paste %></p>
<% end %>
View
2 app/views/pastes/index.html.erb
@@ -41,4 +41,4 @@
:key => User.current.rss_key } %>
<% end %>
-<%= render "sidebar" %>
+<%= render "sidebar" if @project %>
View
2 app/views/pastes/show.html.erb
@@ -34,4 +34,4 @@ table.CodeRay td.line_numbers {
<%= manage_paste_links(@paste) %>
</p>
-<%= render "sidebar" %>
+<%= render "sidebar" if @project %>
View
4 config/routes.rb
@@ -1,6 +1,8 @@
ActionController::Routing::Routes.draw do |map|
- map.resources :pastes, :only => [:index, :show],
+ # new paste can be only created on a project
+ map.resources :pastes, :except => :new,
:member => { :download => :get }
+
map.resources :pastes, :path_prefix => '/projects/:project_id',
:member => { :download => :get }
end

0 comments on commit 1331046

Please sign in to comment.