Skip to content

Commit

Permalink
Use named routes in controllers.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10981 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Dec 11, 2012
1 parent cf66561 commit 0b96094
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 39 deletions.
6 changes: 3 additions & 3 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def register
session[:auth_source_registration] = nil
self.logged_user = @user
flash[:notice] = l(:notice_account_activated)
redirect_to :controller => 'my', :action => 'account'
redirect_to my_account_path
end
else
@user.login = params[:user][:login]
Expand Down Expand Up @@ -218,7 +218,7 @@ def successful_authentication(user)
set_autologin_cookie(user)
end
call_hook(:controller_account_success_authentication_after, {:user => user })
redirect_back_or_default :controller => 'my', :action => 'page'
redirect_back_or_default my_page_path
end

def set_autologin_cookie(user)
Expand Down Expand Up @@ -270,7 +270,7 @@ def register_automatically(user, &block)
if user.save
self.logged_user = user
flash[:notice] = l(:notice_account_activated)
redirect_to :controller => 'my', :action => 'account'
redirect_to my_account_path
else
yield if block_given?
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def default_configuration
flash[:error] = l(:error_can_t_load_default_data, e.message)
end
end
redirect_to :action => 'index'
redirect_to admin_path
end

def test_email
Expand All @@ -68,7 +68,7 @@ def test_email
flash[:error] = l(:notice_email_error, e.message)
end
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications'
redirect_to settings_path(:tab => 'notifications')
end

def info
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/auth_sources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create
@auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
if @auth_source.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index'
redirect_to auth_sources_path
else
render :action => 'new'
end
Expand All @@ -48,7 +48,7 @@ def update
@auth_source = AuthSource.find(params[:id])
if @auth_source.update_attributes(params[:auth_source])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index'
redirect_to auth_sources_path
else
render :action => 'edit'
end
Expand All @@ -62,7 +62,7 @@ def test_connection
rescue Exception => e
flash[:error] = l(:error_unable_to_connect, e.message)
end
redirect_to :action => 'index'
redirect_to auth_sources_path
end

def destroy
Expand All @@ -71,6 +71,6 @@ def destroy
@auth_source.destroy
flash[:notice] = l(:notice_successful_delete)
end
redirect_to :action => 'index'
redirect_to auth_sources_path
end
end
2 changes: 1 addition & 1 deletion app/controllers/boards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def destroy

private
def redirect_to_settings_in_projects
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
redirect_to settings_project_path(@project, :tab => 'boards')
end

def find_board_if_available
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def create
flash[:notice] = l(:label_comment_added)
end

redirect_to :controller => 'news', :action => 'show', :id => @news
redirect_to news_path(@news)
end

def destroy
@news.comments.find(params[:comment_id]).destroy
redirect_to :controller => 'news', :action => 'show', :id => @news
redirect_to news_path(@news)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/custom_fields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create
if request.post? and @custom_field.save
flash[:notice] = l(:notice_successful_create)
call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
redirect_to :action => 'index', :tab => @custom_field.class.name
redirect_to custom_fields_path(:tab => @custom_field.class.name)
else
render :action => 'new'
end
Expand All @@ -47,18 +47,18 @@ def update
if request.put? and @custom_field.update_attributes(params[:custom_field])
flash[:notice] = l(:notice_successful_update)
call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
redirect_to :action => 'index', :tab => @custom_field.class.name
redirect_to custom_fields_path(:tab => @custom_field.class.name)
else
render :action => 'edit'
end
end

def destroy
@custom_field.destroy
redirect_to :action => 'index', :tab => @custom_field.class.name
redirect_to custom_fields_path(:tab => @custom_field.class.name)
rescue
flash[:error] = l(:error_can_not_delete_custom_field)
redirect_to :action => 'index'
redirect_to custom_fields_path(:tab => @custom_field.class.name)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create
if @document.save
render_attachment_warning_if_needed(@document)
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index', :project_id => @project
redirect_to project_documents_path(@project)
else
render :action => 'new'
end
Expand All @@ -71,15 +71,15 @@ def update
@document.safe_attributes = params[:document]
if request.put? and @document.save
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @document
redirect_to document_path(@document)
else
render :action => 'edit'
end
end

def destroy
@document.destroy if request.delete?
redirect_to :controller => 'documents', :action => 'index', :project_id => @project
redirect_to project_documents_path(@project)
end

def add_attachment
Expand All @@ -89,6 +89,6 @@ def add_attachment
if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
Mailer.attachments_added(attachments[:files]).deliver
end
redirect_to :action => 'show', :id => @document
redirect_to document_path(@document)
end
end
8 changes: 4 additions & 4 deletions app/controllers/enumerations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def new
def create
if request.post? && @enumeration.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index'
redirect_to enumerations_path
else
render :action => 'new'
end
Expand All @@ -58,7 +58,7 @@ def edit
def update
if request.put? && @enumeration.update_attributes(params[:enumeration])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index'
redirect_to enumerations_path
else
render :action => 'edit'
end
Expand All @@ -68,12 +68,12 @@ def destroy
if !@enumeration.in_use?
# No associated objects
@enumeration.destroy
redirect_to :action => 'index'
redirect_to enumerations_path
return
elsif params[:reassign_to_id]
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
@enumeration.destroy(reassign_to)
redirect_to :action => 'index'
redirect_to enumerations_path
return
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def destroy
@group.destroy

respond_to do |format|
format.html { redirect_to(groups_url) }
format.html { redirect_to(groups_path) }
format.api { render_api_ok }
end
end
Expand All @@ -93,7 +93,7 @@ def add_users
@users = User.find_all_by_id(params[:user_id] || params[:user_ids])
@group.users << @users if request.post?
respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
format.html { redirect_to edit_group_path(@group, :tab => 'users') }
format.js
format.api { render_api_ok }
end
Expand All @@ -102,7 +102,7 @@ def add_users
def remove_user
@group.users.delete(User.find(params[:user_id])) if request.delete?
respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
format.html { redirect_to edit_group_path(@group, :tab => 'users') }
format.js
format.api { render_api_ok }
end
Expand All @@ -117,15 +117,15 @@ def edit_membership
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
@membership.save if request.post?
respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
format.js
end
end

def destroy_membership
Member.find(params[:membership_id]).destroy if request.post?
respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
format.js
end
end
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/issue_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class IssueCategoriesController < ApplicationController

def index
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
format.html { redirect_to_settings_in_projects }
format.api { @categories = @project.issue_categories.all }
end
end

def show
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
format.html { redirect_to_settings_in_projects }
format.api
end
end
Expand All @@ -55,7 +55,7 @@ def create
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
redirect_to_settings_in_projects
end
format.js
format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
Expand All @@ -78,7 +78,7 @@ def update
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
redirect_to_settings_in_projects
}
format.api { render_api_ok }
end
Expand All @@ -99,15 +99,20 @@ def destroy
end
@category.destroy(reassign_to)
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
format.html { redirect_to_settings_in_projects }
format.api { render_api_ok }
end
return
end
@categories = @project.issue_categories - [@category]
end

private
private

def redirect_to_settings_in_projects
redirect_to settings_project_path(@project, :tab => 'categories')
end

# Wrap ApplicationController's find_model_object method to set
# @category instead of just @issue_category
def find_model_object
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/issue_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create
saved = @relation.save

respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
format.html { redirect_to issue_path(@issue) }
format.js {
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
}
Expand All @@ -67,7 +67,7 @@ def destroy
@relation.destroy

respond_to do |format|
format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
format.html { redirect_to issue_path(@relation.issue_from) }
format.js
format.api { render_api_ok }
end
Expand Down
Loading

0 comments on commit 0b96094

Please sign in to comment.