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@10983 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Dec 11, 2012
1 parent 60d06d8 commit 8ab9215
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 88 deletions.
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ def back_url
url
end

# Returns the path to project issues or to the cross-project
# issue list if project is nil
def _issues_path(project, *args)
if project
project_issues_path(project, *args)
else
issues_path(*args)
end
end

def redirect_back_or_default(default)
back_url = params[:back_url].to_s
if back_url.present?
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/issue_statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create
@issue_status = IssueStatus.new(params[:issue_status])
if request.post? && @issue_status.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index'
redirect_to issue_statuses_path
else
render :action => 'new'
end
Expand All @@ -56,18 +56,18 @@ def update
@issue_status = IssueStatus.find(params[:id])
if request.put? && @issue_status.update_attributes(params[:issue_status])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index'
redirect_to issue_statuses_path
else
render :action => 'edit'
end
end

def destroy
IssueStatus.find(params[:id]).destroy
redirect_to :action => 'index'
redirect_to issue_statuses_path
rescue
flash[:error] = l(:error_unable_delete_issue_status)
redirect_to :action => 'index'
redirect_to issue_statuses_path
end

def update_issue_done_ratio
Expand All @@ -76,6 +76,6 @@ def update_issue_done_ratio
else
flash[:error] = l(:error_issue_done_ratios_not_updated)
end
redirect_to :action => 'index'
redirect_to issue_statuses_path
end
end
18 changes: 11 additions & 7 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ def create
format.html {
render_attachment_warning_if_needed(@issue)
flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
{ :action => 'show', :id => @issue })
if params[:continue]
attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
redirect_to new_project_issue_path(@issue.project, :issue => attrs)
else
redirect_to issue_path(@issue)
end
}
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
end
Expand Down Expand Up @@ -187,7 +191,7 @@ def update
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?

respond_to do |format|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
format.html { redirect_back_or_default issue_path(@issue) }
format.api { render_api_ok }
end
else
Expand Down Expand Up @@ -270,12 +274,12 @@ def bulk_update

if params[:follow]
if @issues.size == 1 && moved_issues.size == 1
redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
redirect_to issue_path(moved_issues.first)
elsif moved_issues.map(&:project).uniq.size == 1
redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
redirect_to project_issues_path(moved_issues.map(&:project).first)
end
else
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
redirect_back_or_default _issues_path(@project)
end
end

Expand Down Expand Up @@ -308,7 +312,7 @@ def destroy
end
end
respond_to do |format|
format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
format.html { redirect_back_or_default _issues_path(@project) }
format.api { render_api_ok }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/journals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def edit
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
format.html { redirect_to issue_path(@journal.journalized) }
format.js { render :action => 'update' }
end
else
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create
end

respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
format.html { redirect_to_settings_in_projects }
format.js { @members = members }
format.api {
@member = members.first
Expand All @@ -82,7 +82,7 @@ def update
end
saved = @member.save
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
format.html { redirect_to_settings_in_projects }
format.js
format.api {
if saved
Expand All @@ -99,7 +99,7 @@ def destroy
@member.destroy
end
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
format.html { redirect_to_settings_in_projects }
format.js
format.api {
if @member.destroyed?
Expand All @@ -115,4 +115,10 @@ def autocomplete
@principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
render :layout => false
end

private

def redirect_to_settings_in_projects
redirect_to settings_project_path(@project, :tab => 'members')
end
end
16 changes: 8 additions & 8 deletions app/controllers/my_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def account
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
set_language_if_valid @user.language
flash[:notice] = l(:notice_account_updated)
redirect_to :action => 'account'
redirect_to my_account_path
return
end
end
Expand All @@ -69,7 +69,7 @@ def account
def destroy
@user = User.current
unless @user.own_account_deletable?
redirect_to :action => 'account'
redirect_to my_account_path
return
end

Expand All @@ -88,15 +88,15 @@ def password
@user = User.current
unless @user.change_password_allowed?
flash[:error] = l(:notice_can_t_change_password)
redirect_to :action => 'account'
redirect_to my_account_path
return
end
if request.post?
if @user.check_password?(params[:password])
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
if @user.save
flash[:notice] = l(:notice_account_password_updated)
redirect_to :action => 'account'
redirect_to my_account_path
end
else
flash[:error] = l(:notice_account_wrong_password)
Expand All @@ -114,7 +114,7 @@ def reset_rss_key
User.current.rss_key
flash[:notice] = l(:notice_feeds_access_key_reseted)
end
redirect_to :action => 'account'
redirect_to my_account_path
end

# Create a new API key
Expand All @@ -127,7 +127,7 @@ def reset_api_key
User.current.api_key
flash[:notice] = l(:notice_api_access_key_reseted)
end
redirect_to :action => 'account'
redirect_to my_account_path
end

# User's page layout configuration
Expand Down Expand Up @@ -156,7 +156,7 @@ def add_block
layout['top'].unshift block
@user.pref[:my_page_layout] = layout
@user.pref.save
redirect_to :action => 'page_layout'
redirect_to my_page_layout_path
end

# Remove a block to user's page
Expand All @@ -169,7 +169,7 @@ def remove_block
%w(top left right).each {|f| (layout[f] ||= []).delete block }
@user.pref[:my_page_layout] = layout
@user.pref.save
redirect_to :action => 'page_layout'
redirect_to my_page_layout_path
end

# Change blocks order on user's page
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'news', :action => 'index', :project_id => @project
redirect_to project_news_index_path(@project)
else
render :action => 'new'
end
Expand All @@ -88,15 +88,15 @@ def update
if @news.save
render_attachment_warning_if_needed(@news)
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @news
redirect_to news_path(@news)
else
render :action => 'edit'
end
end

def destroy
@news.destroy
redirect_to :action => 'index', :project_id => @project
redirect_to project_news_index_path(@project)
end

private
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/project_enumerations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ def update
flash[:notice] = l(:notice_successful_update)
end

redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
redirect_to settings_project_path(@project, :tab => 'activities')
end

def destroy
@project.time_entry_activities.each do |time_entry_activity|
time_entry_activity.destroy(time_entry_activity.parent)
end
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
redirect_to settings_project_path(@project, :tab => 'activities')
end

end
25 changes: 13 additions & 12 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ def create
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
redirect_to(params[:continue] ?
{:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} :
{:controller => 'projects', :action => 'settings', :id => @project}
)
if params[:continue]
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_path(attrs)
else
redirect_to settings_project_path(@project)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
end
Expand All @@ -103,7 +105,6 @@ def create
format.api { render_validation_errors(@project) }
end
end

end

def copy
Expand All @@ -120,13 +121,13 @@ def copy
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'projects', :action => 'settings', :id => @project
redirect_to settings_project_path(@project)
elsif !@project.new_record?
# Project was created
# But some objects were not copied due to validation failures
# (eg. issues from disabled trackers)
# TODO: inform about that
redirect_to :controller => 'projects', :action => 'settings', :id => @project
redirect_to settings_project_path(@project)
end
end
end
Expand Down Expand Up @@ -182,7 +183,7 @@ def update
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'settings', :id => @project
redirect_to settings_project_path(@project)
}
format.api { render_api_ok }
end
Expand All @@ -200,7 +201,7 @@ def update
def modules
@project.enabled_module_names = params[:enabled_module_names]
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
redirect_to settings_project_path(@project, :tab => 'modules')
end

def archive
Expand All @@ -209,12 +210,12 @@ def archive
flash[:error] = l(:error_can_not_archive_project)
end
end
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
redirect_to admin_projects_path(:status => params[:status])
end

def unarchive
@project.unarchive if request.post? && !@project.active?
redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
redirect_to admin_projects_path(:status => params[:status])
end

def close
Expand All @@ -233,7 +234,7 @@ def destroy
if api_request? || params[:confirm]
@project_to_destroy.destroy
respond_to do |format|
format.html { redirect_to :controller => 'admin', :action => 'projects' }
format.html { redirect_to admin_projects_path }
format.api { render_api_ok }
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create

if @query.save
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
redirect_to _issues_path(@project, :query_id => @query)
else
render :action => 'new', :layout => !request.xhr?
end
Expand All @@ -78,15 +78,15 @@ def update

if @query.save
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
redirect_to _issues_path(@project, :query_id => @query)
else
render :action => 'edit'
end
end

def destroy
@query.destroy
redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
redirect_to _issues_path(@project, :set_filter => 1)
end

private
Expand Down
Loading

0 comments on commit 8ab9215

Please sign in to comment.