diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
commit | 2d1866d966d94c688f9cb87c5bf3f096dffac844 (patch) | |
tree | 7a733c1cc51448ab69b3f892285305dbfb0ae15e /app/controllers | |
parent | a6ec78a4dc658e3517ed682792016b6530458696 (diff) | |
download | redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.tar.gz redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.zip |
Merged rails-4.1 branch (#14534).
git-svn-id: http://svn.redmine.org/redmine/trunk@13482 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
31 files changed, 109 insertions, 93 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c2d464d42..b0e5ce6fa 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -34,7 +34,7 @@ class AdminController < ApplicationController scope = Project.status(@status).order('lft') scope = scope.like(params[:name]) if params[:name].present? - @projects = scope.all + @projects = scope.to_a render :action => "projects", :layout => false if request.xhr? end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8f3565ee..7fedd44ff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -496,7 +496,7 @@ class ApplicationController < ActionController::Base end def render_feed(items, options={}) - @items = items || [] + @items = (items || []).to_a @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } @items = @items.slice(0, Setting.feeds_limit.to_i) @title = options[:title] || Setting.app_title diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index a48afdf90..991f0be16 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -26,7 +26,7 @@ class AutoCompletesController < ApplicationController if q.match(/\A#?(\d+)\z/) @issues << scope.find_by_id($1.to_i) end - @issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).all + @issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).to_a @issues.compact! end render :layout => false diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 1f1d47342..04bdb56c0 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -25,7 +25,7 @@ class BoardsController < ApplicationController helper :watchers def index - @boards = @project.boards.includes(:project, :last_message => :author).all + @boards = @project.boards.preload(:project, :last_message => :author).to_a # show the board if there is only one if @boards.size == 1 @board = @boards.first @@ -45,12 +45,13 @@ class BoardsController < ApplicationController @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] @topics = @board.topics. reorder("#{Message.table_name}.sticky DESC"). - includes(:last_reply). + joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id"). + references(:last_reply). limit(@topic_pages.per_page). offset(@topic_pages.offset). order(sort_clause). preload(:author, {:last_reply => :author}). - all + to_a @message = Message.new(:board => @board) render :action => 'show', :layout => !request.xhr? } @@ -59,7 +60,7 @@ class BoardsController < ApplicationController reorder('created_on DESC'). includes(:author, :board). limit(Setting.feeds_limit.to_i). - all + to_a render_feed(@messages, :title => "#{@project}: #{@board}") } end diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 43cfc2530..47065f934 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -27,7 +27,7 @@ class DocumentsController < ApplicationController def index @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - documents = @project.documents.includes(:attachments, :category).all + documents = @project.documents.includes(:attachments, :category).to_a case @sort_by when 'date' @grouped = documents.group_by {|d| d.updated_on.to_date } @@ -43,7 +43,7 @@ class DocumentsController < ApplicationController end def show - @attachments = @document.attachments.all + @attachments = @document.attachments.to_a end def new @@ -69,7 +69,7 @@ class DocumentsController < ApplicationController def update @document.safe_attributes = params[:document] - if request.put? and @document.save + if @document.save flash[:notice] = l(:notice_successful_update) redirect_to document_path(@document) else diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb index 65a503974..d8d9141bb 100644 --- a/app/controllers/enumerations_controller.rb +++ b/app/controllers/enumerations_controller.rb @@ -32,7 +32,7 @@ class EnumerationsController < ApplicationController format.api { @klass = Enumeration.get_subclass(params[:type]) if @klass - @enumerations = @klass.shared.sorted.all + @enumerations = @klass.shared.sorted.to_a else render_404 end @@ -56,7 +56,7 @@ class EnumerationsController < ApplicationController end def update - if request.put? && @enumeration.update_attributes(params[:enumeration]) + if @enumeration.update_attributes(params[:enumeration]) flash[:notice] = l(:notice_successful_update) redirect_to enumerations_path else @@ -75,7 +75,7 @@ class EnumerationsController < ApplicationController redirect_to enumerations_path return end - @enumerations = @enumeration.class.system.all - [@enumeration] + @enumerations = @enumeration.class.system.to_a - [@enumeration] end private diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 6ba5c110c..f3eb6719f 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -31,8 +31,10 @@ class FilesController < ApplicationController 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" - @containers = [ Project.includes(:attachments).reorder(sort_clause).find(@project.id)] - @containers += @project.versions.includes(:attachments).reorder(sort_clause).all.sort.reverse + @containers = [Project.includes(:attachments). + references(:attachments).reorder(sort_clause).find(@project.id)] + @containers += @project.versions.includes(:attachments). + references(:attachments).reorder(sort_clause).to_a.sort.reverse render :layout => !request.xhr? end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 555fc61df..45ed4c4e1 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -27,13 +27,13 @@ class GroupsController < ApplicationController def index respond_to do |format| format.html { - @groups = Group.sorted.all + @groups = Group.sorted.to_a @user_count_by_group_id = user_count_by_group_id } format.api { scope = Group.sorted scope = scope.givable unless params[:builtin] == '1' - @groups = scope.all + @groups = scope.to_a } end end @@ -95,7 +95,7 @@ class GroupsController < ApplicationController end def add_users - @users = User.where(:id => (params[:user_id] || params[:user_ids])).all + @users = User.where(:id => (params[:user_id] || params[:user_ids])).to_a @group.users << @users if request.post? respond_to do |format| format.html { redirect_to edit_group_path(@group, :tab => 'users') } diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index 6a956904a..3c73510ee 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -27,7 +27,7 @@ class IssueCategoriesController < ApplicationController def index respond_to do |format| format.html { redirect_to_settings_in_projects } - format.api { @categories = @project.issue_categories.all } + format.api { @categories = @project.issue_categories.to_a } end end diff --git a/app/controllers/issue_statuses_controller.rb b/app/controllers/issue_statuses_controller.rb index d305dedd7..a6b72f329 100644 --- a/app/controllers/issue_statuses_controller.rb +++ b/app/controllers/issue_statuses_controller.rb @@ -29,7 +29,7 @@ class IssueStatusesController < ApplicationController render :action => "index", :layout => false if request.xhr? } format.api { - @issue_statuses = IssueStatus.order('position').all + @issue_statuses = IssueStatus.order('position').to_a } end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index de346c576..5623c3bfa 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -104,15 +104,16 @@ class IssuesController < ApplicationController end def show - @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all + @journals = @issue.journals.includes(:user, :details). + references(:user, :details). + reorder("#{Journal.table_name}.id ASC").to_a @journals.each_with_index {|j,i| j.indice = i+1} @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) Journal.preload_journals_details_custom_fields(@journals) - # TODO: use #select! when ruby1.8 support is dropped - @journals.reject! {|journal| !journal.notes? && journal.visible_details.empty?} + @journals.select! {|journal| journal.notes? || journal.visible_details.any?} @journals.reverse! if User.current.wants_comments_in_reverse_order? - @changesets = @issue.changesets.visible.all + @changesets = @issue.changesets.visible.to_a @changesets.reverse! if User.current.wants_comments_in_reverse_order? @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } @@ -189,7 +190,7 @@ class IssuesController < ApplicationController rescue ActiveRecord::StaleObjectError @conflict = true if params[:last_journal_id] - @conflict_journals = @issue.journals_after(params[:last_journal_id]).all + @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) end end @@ -301,7 +302,7 @@ class IssuesController < ApplicationController else @saved_issues = @issues @unsaved_issues = unsaved_issues - @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).all + @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a bulk_edit render :action => 'bulk_edit' end @@ -375,7 +376,9 @@ class IssuesController < ApplicationController def update_issue_from_params @edit_allowed = User.current.allowed_to?(:edit_issues, @project) @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) - @time_entry.attributes = params[:time_entry] + if params[:time_entry] + @time_entry.attributes = params[:time_entry] + end @issue.init_journal(User.current) @@ -422,7 +425,9 @@ class IssuesController < ApplicationController @issue.project = @project @issue.author ||= User.current # Tracker must be set before custom field values - @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) + tracker_id = (params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] + tracker = tracker_id.present? ? @project.trackers.find(tracker_id) : @project.trackers.first + @issue.tracker ||= tracker if @issue.tracker.nil? render_error l(:error_no_tracker_in_project) return false diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index fe1c01907..940a7b5e1 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -34,7 +34,6 @@ class JournalsController < ApplicationController retrieve_query sort_init 'id', 'desc' sort_update(@query.sortable_columns) - if @query.valid? @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", :limit => 25) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index aca136754..ca5002af8 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -32,7 +32,7 @@ class MembersController < ApplicationController order("#{Member.table_name}.id"). limit(@limit). offset(@offset). - all + to_a respond_to do |format| format.html { head 406 } format.api @@ -63,7 +63,10 @@ class MembersController < ApplicationController respond_to do |format| format.html { redirect_to_settings_in_projects } - format.js { @members = members } + format.js { + @members = members + @member = Member.new + } format.api { @member = members.first if @member.valid? diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0eb9f0bef..aa0788a05 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -43,10 +43,10 @@ class MessagesController < ApplicationController @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page @replies = @topic.children. includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on ASC"). + reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC"). limit(@reply_pages.per_page). offset(@reply_pages.offset). - all + to_a @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => false if request.xhr? diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 714b23857..4fd18bab0 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -53,8 +53,8 @@ class MyController < ApplicationController @user = User.current @pref = @user.pref if request.post? - @user.safe_attributes = params[:user] - @user.pref.attributes = params[:pref] + @user.safe_attributes = params[:user] if params[:user] + @user.pref.attributes = params[:pref] if params[:pref] if @user.save @user.pref.save set_language_if_valid @user.language diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index ffe662921..50c0489f4 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -46,7 +46,7 @@ class NewsController < ApplicationController order("#{News.table_name}.created_on DESC"). limit(@limit). offset(@offset). - all + to_a respond_to do |format| format.html { @news = News.new # for adding news inline diff --git a/app/controllers/project_enumerations_controller.rb b/app/controllers/project_enumerations_controller.rb index 2475dbf65..df4fcbf23 100644 --- a/app/controllers/project_enumerations_controller.rb +++ b/app/controllers/project_enumerations_controller.rb @@ -20,7 +20,7 @@ class ProjectEnumerationsController < ApplicationController before_filter :authorize def update - if request.put? && params[:enumerations] + if params[:enumerations] Project.transaction do params[:enumerations].each do |id, activity| @project.update_or_create_time_entry_activity(id, activity) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1225f2f01..0a6b487a8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -53,30 +53,30 @@ class ProjectsController < ApplicationController unless params[:closed] scope = scope.active end - @projects = scope.visible.order('lft').all + @projects = scope.visible.order('lft').to_a } format.api { @offset, @limit = api_offset_and_limit @project_count = Project.visible.count - @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + @projects = Project.visible.offset(@offset).limit(@limit).order('lft').to_a } format.atom { - projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).to_a render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") } end end def new - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all + @issue_custom_fields = IssueCustomField.sorted.to_a + @trackers = Tracker.sorted.to_a @project = Project.new @project.safe_attributes = params[:project] end def create - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all + @issue_custom_fields = IssueCustomField.sorted.to_a + @trackers = Tracker.sorted.to_a @project = Project.new @project.safe_attributes = params[:project] @@ -109,8 +109,8 @@ class ProjectsController < ApplicationController end def copy - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all + @issue_custom_fields = IssueCustomField.sorted.to_a + @trackers = Tracker.sorted.to_a @source_project = Project.find(params[:id]) if request.get? @project = Project.copy_from(@source_project) @@ -145,8 +145,8 @@ class ProjectsController < ApplicationController end @users_by_role = @project.users_by_role - @subprojects = @project.children.visible.all - @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all + @subprojects = @project.children.visible.to_a + @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a @trackers = @project.rolled_up_trackers cond = @project.project_condition(Setting.display_subprojects_issues?) @@ -167,10 +167,10 @@ class ProjectsController < ApplicationController end def settings - @issue_custom_fields = IssueCustomField.sorted.all + @issue_custom_fields = IssueCustomField.sorted.to_a @issue_category ||= IssueCategory.new @member ||= @project.members.new - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.to_a @wiki ||= @project.wiki end diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 049e3534b..22ec9e929 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -37,8 +37,9 @@ class QueriesController < ApplicationController order("#{Query.table_name}.name"). limit(@limit). offset(@offset). - all + to_a respond_to do |format| + format.html {render_error :status => 406} format.api end end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 00c94a106..43dac3673 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -90,6 +90,6 @@ class ReportsController < ApplicationController private def find_issue_statuses - @statuses = IssueStatus.sorted.all + @statuses = IssueStatus.sorted.to_a end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 59afc5529..7eb72865b 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -69,7 +69,7 @@ class RepositoriesController < ApplicationController @repository.merge_extra_info(attrs[:attrs_extra]) end @repository.project = @project - if request.put? && @repository.save + if @repository.save redirect_to settings_project_path(@project, :tab => 'repositories') else render :action => 'edit' @@ -94,7 +94,7 @@ class RepositoriesController < ApplicationController @committers = @repository.committers @users = @project.users additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) - @users += User.where(:id => additional_user_ids).all unless additional_user_ids.empty? + @users += User.where(:id => additional_user_ids).to_a unless additional_user_ids.empty? @users.compact! @users.sort! if request.post? && params[:committers].is_a?(Hash) @@ -145,7 +145,7 @@ class RepositoriesController < ApplicationController limit(@changeset_pages.per_page). offset(@changeset_pages.offset). includes(:user, :repository, :parents). - all + to_a respond_to do |format| format.html { render :layout => false if request.xhr? } diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 8a976779e..a74d8bb91 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -30,7 +30,7 @@ class RolesController < ApplicationController render :action => "index", :layout => false if request.xhr? } format.api { - @roles = Role.givable.all + @roles = Role.givable.to_a } end end @@ -47,7 +47,7 @@ class RolesController < ApplicationController if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) @role.copy_from(@copy_from) end - @roles = Role.sorted.all + @roles = Role.sorted.to_a end def create @@ -60,7 +60,7 @@ class RolesController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_to roles_path else - @roles = Role.sorted.all + @roles = Role.sorted.to_a render :action => 'new' end end @@ -69,7 +69,7 @@ class RolesController < ApplicationController end def update - if request.put? and @role.update_attributes(params[:role]) + if @role.update_attributes(params[:role]) flash[:notice] = l(:notice_successful_update) redirect_to roles_path else @@ -86,7 +86,7 @@ class RolesController < ApplicationController end def permissions - @roles = Role.sorted.all + @roles = Role.sorted.to_a @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } if request.post? @roles.each do |role| diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index afc756677..ec8b4812c 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -31,7 +31,7 @@ class SearchController < ApplicationController when 'my_projects' User.current.memberships.collect(&:project) when 'subprojects' - @project ? (@project.self_and_descendants.active.all) : nil + @project ? (@project.self_and_descendants.active.to_a) : nil else @project end diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb index d8ef783eb..0b62b420c 100644 --- a/app/controllers/sys_controller.rb +++ b/app/controllers/sys_controller.rb @@ -19,7 +19,8 @@ class SysController < ActionController::Base before_filter :check_enabled def projects - p = Project.active.has_module(:repository).order("#{Project.table_name}.identifier").preload(:repository).all + p = Project.active.has_module(:repository). + order("#{Project.table_name}.identifier").preload(:repository).to_a # extra_info attribute from repository breaks activeresource client render :xml => p.to_xml( :only => [:id, :identifier, :name, :is_public, :status], @@ -56,7 +57,7 @@ class SysController < ActionController::Base raise ActiveRecord::RecordNotFound unless project projects << project else - projects = scope.all + projects = scope.to_a end projects.each do |project| project.repositories.each do |repository| diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 13923b1e5..20eccef71 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -52,7 +52,7 @@ class TimelogController < ApplicationController format.html { @entry_count = scope.count @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] - @entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).all + @entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).to_a @total_hours = scope.sum(:hours).to_f render :layout => !request.xhr? @@ -60,15 +60,15 @@ class TimelogController < ApplicationController format.api { @entry_count = scope.count @offset, @limit = api_offset_and_limit - @entries = scope.offset(@offset).limit(@limit).preload(:custom_values => :custom_field).all + @entries = scope.offset(@offset).limit(@limit).preload(:custom_values => :custom_field).to_a } format.atom { - entries = scope.limit(Setting.feeds_limit.to_i).reorder("#{TimeEntry.table_name}.created_on DESC").all + entries = scope.limit(Setting.feeds_limit.to_i).reorder("#{TimeEntry.table_name}.created_on DESC").to_a render_feed(entries, :title => l(:label_spent_time)) } format.csv { # Export all entries - @entries = scope.all + @entries = scope.to_a send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') } end @@ -232,7 +232,7 @@ private end def find_time_entries - @time_entries = TimeEntry.where(:id => params[:id] || params[:ids]).all + @time_entries = TimeEntry.where(:id => params[:id] || params[:ids]).to_a raise ActiveRecord::RecordNotFound if @time_entries.empty? @projects = @time_entries.collect(&:project).compact.uniq @project = @projects.first if @projects.size == 1 diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 02274d0d3..ec0b9ce3f 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -29,14 +29,14 @@ class TrackersController < ApplicationController render :action => "index", :layout => false if request.xhr? } format.api { - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.to_a } end end def new @tracker ||= Tracker.new(params[:tracker]) - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.to_a @projects = Project.all end @@ -95,7 +95,7 @@ class TrackersController < ApplicationController redirect_to fields_trackers_path return end - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.to_a @custom_fields = IssueCustomField.all.sort end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c5db58988..bb56fb285 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -47,7 +47,7 @@ class UsersController < ApplicationController @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] @offset ||= @user_pages.offset - @users = scope.order(sort_clause).limit(@limit).offset(@offset).all + @users = scope.order(sort_clause).limit(@limit).offset(@offset).to_a respond_to do |format| format.html { @@ -60,7 +60,7 @@ class UsersController < ApplicationController def show # show projects based on current user visibility - @memberships = @user.memberships.where(Project.visible_condition(User.current)).all + @memberships = @user.memberships.where(Project.visible_condition(User.current)).to_a events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) @events_by_day = events.group_by(&:event_date) @@ -90,7 +90,7 @@ class UsersController < ApplicationController @user.admin = params[:user][:admin] || false @user.login = params[:user][:login] @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id - @user.pref.attributes = params[:pref] + @user.pref.attributes = params[:pref] if params[:pref] if @user.save Mailer.account_information(@user, @user.password).deliver if params[:send_information] @@ -134,7 +134,7 @@ class UsersController < ApplicationController # Was the account actived ? (do it before User#save clears the change) was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) # TODO: Similar to My#account - @user.pref.attributes = params[:pref] + @user.pref.attributes = params[:pref] if params[:pref] if @user.save @user.pref.save diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index a49f8a09a..bf2315321 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -31,7 +31,7 @@ class VersionsController < ApplicationController def index respond_to do |format| format.html { - @trackers = @project.trackers.sorted.all + @trackers = @project.trackers.sorted.to_a retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?}) @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] @@ -56,7 +56,7 @@ class VersionsController < ApplicationController @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} } format.api { - @versions = @project.shared_versions.all + @versions = @project.shared_versions.to_a } end end @@ -67,7 +67,7 @@ class VersionsController < ApplicationController @issues = @version.fixed_issues.visible. includes(:status, :tracker, :priority). reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id"). - all + to_a } format.api end @@ -117,7 +117,7 @@ class VersionsController < ApplicationController end def update - if request.put? && params[:version] + if params[:version] attributes = params[:version].dup attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) @version.safe_attributes = attributes diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index e6c4d3119..ade977b41 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -53,7 +53,7 @@ class WatchersController < ApplicationController def append if params[:watcher].is_a?(Hash) user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] - @users = User.active.where(:id => user_ids).all + @users = User.active.where(:id => user_ids).to_a end if @users.blank? render :nothing => true @@ -92,7 +92,7 @@ class WatchersController < ApplicationController def find_watchables klass = Object.const_get(params[:object_type].camelcase) rescue nil if klass && klass.respond_to?('watched_by') - @watchables = klass.where(:id => Array.wrap(params[:object_id])).all + @watchables = klass.where(:id => Array.wrap(params[:object_id])).to_a raise Unauthorized if @watchables.any? {|w| if w.respond_to?(:visible?) !w.visible? diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 723c7191d..9b3981655 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -219,7 +219,7 @@ class WikiController < ApplicationController reorder('version DESC'). limit(@version_pages.per_page + 1). offset(@version_pages.offset). - all + to_a render :layout => false if request.xhr? end @@ -280,7 +280,7 @@ class WikiController < ApplicationController @pages = @wiki.pages. order('title'). includes([:content, {:attachments => :author}]). - all + to_a respond_to do |format| format.html { export = render_to_string :action => 'export_multiple', :layout => false @@ -327,7 +327,7 @@ private def find_existing_or_new_page @page = @wiki.find_or_new_page(params[:id]) if @wiki.page_found_with_redirect? - redirect_to params.update(:id => @page.title) + redirect_to_page @page end end @@ -339,10 +339,14 @@ private return end if @wiki.page_found_with_redirect? - redirect_to params.update(:id => @page.title) + redirect_to_page @page end end + def redirect_to_page(page) + redirect_to :action => action_name, :project_id => page.wiki.project, :id => page.title + end + # Returns true if the current user is allowed to edit the page, otherwise false def editable?(page = @page) page.editable_by?(User.current) @@ -360,6 +364,6 @@ private reorder("#{WikiPage.table_name}.title"). includes(:wiki => :project). includes(:parent). - all + to_a end end diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index fd700d25e..28b0f2242 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -86,9 +86,9 @@ class WorkflowsController < ApplicationController @source_role = Role.find_by_id(params[:source_role_id].to_i) end @target_trackers = params[:target_tracker_ids].blank? ? - nil : Tracker.where(:id => params[:target_tracker_ids]).all + nil : Tracker.where(:id => params[:target_tracker_ids]).to_a @target_roles = params[:target_role_ids].blank? ? - nil : Role.where(:id => params[:target_role_ids]).all + nil : Role.where(:id => params[:target_role_ids]).to_a if request.post? if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) flash.now[:error] = l(:error_workflow_copy_source) @@ -113,9 +113,9 @@ class WorkflowsController < ApplicationController def find_roles ids = Array.wrap(params[:role_id]) if ids == ['all'] - @roles = Role.sorted.all + @roles = Role.sorted.to_a elsif ids.present? - @roles = Role.where(:id => ids).all + @roles = Role.where(:id => ids).to_a end @roles = nil if @roles.blank? end @@ -123,9 +123,9 @@ class WorkflowsController < ApplicationController def find_trackers ids = Array.wrap(params[:tracker_id]) if ids == ['all'] - @trackers = Tracker.sorted.all + @trackers = Tracker.sorted.to_a elsif ids.present? - @trackers = Tracker.where(:id => ids).all + @trackers = Tracker.where(:id => ids).to_a end @trackers = nil if @trackers.blank? end @@ -135,6 +135,6 @@ class WorkflowsController < ApplicationController if @trackers && @used_statuses_only @statuses = @trackers.map(&:issue_statuses).flatten.uniq.sort.presence end - @statuses ||= IssueStatus.sorted.all + @statuses ||= IssueStatus.sorted.to_a end end |