Rails 6 我有一个 select_tag 没有下拉列表
Rails 6 I have a select_tag that is not droping down a list
我正在重写一个名为 Emissions Gateway 的应用程序,从 Rails v3.2 到 Rails v6.1.4.1
我有大约 99% 的应用程序被重写并正常工作,但有一部分让我很困惑。
当您删除用户时,它要求您将他们拥有的任何项目移动到不同的用户。这通常会显示一个下拉菜单。模式正在工作,按钮正在工作,但下拉菜单没有显示任何内容,我一直无法弄清楚为什么?
这是具有 select_tag 的特定部分:
= simple_form_for @user, :html => { :method => :delete } do |f|
= select_tag :user_id, options_from_collection_for_select(users_when_being_deleted(@user), "id", "name")
这是名为 users_helper.rb
的文件中名为 users_when_being_deleted 的方法
def users_when_being_deleted(user = nil)
if user
User.where(vendor_id: "current_user.vendor_id").
and(User.where.not(id: @user.id)).order(:name)
else
User.where(vendor_id: "current_user.vendor_id").order(:name)
end
end
下面是单击向下箭头时模态框的外观图片:
这里是users_controller.rb
中的destroy方法
def destroy
# check for vendor manager
@user = User.find(params[:id])
@vendor = @user.vendor
if (@user.id != @vendor.user_manager_id) && params[:user_id].present?
@user.move_data_to_user(params[:user_id])
@user.destroy
flash[:success] = "User removed."
redirect_to users_url
else
redirect_to users_url, notice: "Cannot delete this user."
end
end
这里是模型中的move_data_to_user方法user.rb
def move_data_to_user(new_user_id)
@new_user = User.find_by_id(new_user_id)
self.articles.each { |a| a.user_id = new_user_id ; a.save }
self.audits.update_all(user_id: nil)
self.projects.each do |project|
Audit.create(class_kind: "project", item_id: project.id, action: "unassigned", new_value: self.name, user_id: User.current_user.id, project_id: project.id)
Audit.create(class_kind: "project", item_id: project.id, action: "assigned", new_value: @new_user.name, user_id: User.current_user.id, project_id: project.id) unless @new_user.nil?
end
self.projects.update_all(user_id: new_user_id, vendor_id: self.vendor_id)
self.verified_projects.update_all(user_verified_id: new_user_id)
self.pending_projects.update_all(user_submitted_id: new_user_id)
@new_user.touch
end
这里是全貌show.html.haml:
- provide(:title, @user.name + " - Profile")
.container-fluid
#pad-wrapper.user-profile
// header
.row-fluid.header
.span8
%h3.name{style: "float:none;"}= @user.name
%span.area #{@user.projects.count} projects
- if can?(:destroy, @user) && (@user.id != @vendor.user_manager_id)
= link_to "#", type: "button", id: "user-delete-shortcut", class: "btn btn-danger icon pull-right delete-user", data: { backdrop: "static", toggle: "modal", target: "#user-delete-modal" } do
%i.icon-trash
#user-delete-modal.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "user-delete-modal", :role => "dialog", :tabindex => "-1"}
.modal-header.clearfix
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
%h3#UserDeleteModal Delete User
.modal-body
.row-fluid
.span12
.alert.alert-warning
%strong
In order to remove this user, you must first reassign their projects to another employee.
.row-fluid
.span6.offset3.center
= simple_form_for @user, :html => { :method => :delete } do |f|
= select_tag :user_id, options_from_collection_for_select(users_when_being_deleted(@user), "id", "name")
%br/
%br/
= f.submit "Move Projects & Destroy User", class: 'btn btn-danger center', data: { confirm: 'Are you sure? This cannot be undone!' }
.modal-footer
%ul.step_nav
%li.next
/ = f.submit class: "btn btn-success", name: "Confirm Delete User", value: "Save"
%li.previous
%button.btn.btn-danger{"aria-hidden" => "true", "data-dismiss" => "modal"} Close
- if can?(:edit, @user)
%a.btn.icon.btn-info.pull-right.large.edit{href: edit_user_path(@user)}
%i.icon-edit
Edit #{@user.name}
.row-fluid.profile
.span9.bio
.row-fluid
.span12
.profile-box
- if @recent_projects.any?
.span6
%h6 Recent projects
%br/
.span6
.span{style: 'padding-right: 10px;'}
= will_paginate(@recent_projects, param_name: 'project_page')
// projects table
.table-projects{style: "font-size: 15px;"}
.row-fluid
%table.table.table-hover
%thead
%tr
%th.span3
Name
%th.span3.hidden-phone
%span.line
Assessment
%th.span3.hidden-phone
%span.line
Datalogs
%th.span3.hidden-phone
%span.line
Pictures
%th.span3
%span.line
Status
%th.span3
%span.line
Created
%tbody
- cache ["v1", @recent_projects] do
= render @recent_projects
- else
%h5.center This user doesn't have any projects yet.
// Disabled notes, can reenable if use arrises
/ .span12.section.comment
/ %h6 Add a quick note
/ %p Add a note about this user to keep a history of your interactions.
/ %textarea
/ .span12.submit-box.pull-right
/ %input.btn-glow.primary{:type => "submit", :value => "Add Note"}/
/ %span OR
/ %input.reset{:type => "reset", :value => "Cancel"}/
.row-fluid
.profile-box
.span12
%h6
%i.icon-star
Wishes
%br/
.row-fluid
-if @wishes.any?
%table.table.table-hover
%thead
%tr
%th.span12
Wish
%th.span3
%span.line
Date
%th.span3
%span.line
Browser
%th.span3{colspan: 3}
%span.line
Status
%tbody
- @wishes.each do |wish|
= render "user_wishes", wish: wish
-else
.center
%h4
%i.icon-info-sign
No wishes have been submitted yet.
%br
%br
.row-fluid
.profile-box
- if @audits.any?
.span6
%h6 Recent Audits
%br/
.span6
.span{style: 'padding-right: 10px;'}
= will_paginate(@audits, param_name: 'audit_page')
// audits table
.table-audits{style: "font-size: 15px;"}
.row-fluid
%table.table.table-hover
%thead
%tr
%th.span3
Timestamp
%th.span3.hidden-phone
%span.line
User
%th.span3.hidden-phone
%span.line
Action
%th.span3.hidden-phone
%span.line
Section
%th.span3.hidden-phone
%span.line
Details
%tbody
- cache ["v1", @audits] do
= render @audits
- else
%h5.center This user doesn't have any projects yet.
// Disabled notes, can reenable if use arrises
/ .span12.section.comment
/ %h6 Add a quick note
/ %p Add a note about this user to keep a history of your interactions.
/ %textarea
/ .span12.submit-box.pull-right
/ %input.btn-glow.primary{:type => "submit", :value => "Add Note"}/
/ %span OR
/ %input.reset{:type => "reset", :value => "Cancel"}/
// side column
.span3.address.pull-right
.row-fluid
%h6.center User Details
#user-more-information.row-fluid.center
.span6
%dl
%dt Vendor
%dd= @user.vendor.name
%dt Role
%dd= @user.role.titleize
%dt Member Since
%dd= @user.created_at.strftime("%B #{@user.created_at.day.ordinalize}, %Y")
.span6
%dl
%dt Last Logged In
%dd= @user.last_sign_in_at ? @user.last_sign_in_at.strftime("%m/%d/%Y") : "Never"
%dt Current IP
%dd= @user.current_sign_in_ip
%dt Last IP
%dd= @user.last_sign_in_ip
.row-fluid.center.section
%h6 Project Stats
#user-project-stats
.span6
%dl
%dt Total
%dd= @user.projects.count
.span6
%dl
%dt Incomplete
%dd= @user.projects.incomplete.count
%dt Prepared
%dd= @user.projects.prepared.count
%dt Pending
%dd= @user.projects.pending.count
%dt Verified
%dd= @user.projects.verified.count
.row-fluid
.span2
= link_to 'Back', vendor_users_path(@user.vendor_id), class: 'btn'
如果有其他人想看什么,请告诉我。我不相信在 bootstrap 模态之外还有任何单独的 JavaScript 在起作用。其他一切都很好。我在控制台中没有收到任何关于任何错误的信息,Rails 控制台中也没有任何错误,就好像一旦进入该模态就没有任何事情发生。我被难住了。
如有任何帮助,我们将不胜感激!
感谢您的时间,
斯科特
我认为问题出在查询上。
改变
User.where(vendor_id: "current_user.vendor_id")
到
User.where(vendor_id: current_user.vendor_id)
我正在重写一个名为 Emissions Gateway 的应用程序,从 Rails v3.2 到 Rails v6.1.4.1
我有大约 99% 的应用程序被重写并正常工作,但有一部分让我很困惑。 当您删除用户时,它要求您将他们拥有的任何项目移动到不同的用户。这通常会显示一个下拉菜单。模式正在工作,按钮正在工作,但下拉菜单没有显示任何内容,我一直无法弄清楚为什么?
这是具有 select_tag 的特定部分:
= simple_form_for @user, :html => { :method => :delete } do |f|
= select_tag :user_id, options_from_collection_for_select(users_when_being_deleted(@user), "id", "name")
这是名为 users_helper.rb
的文件中名为 users_when_being_deleted 的方法 def users_when_being_deleted(user = nil)
if user
User.where(vendor_id: "current_user.vendor_id").
and(User.where.not(id: @user.id)).order(:name)
else
User.where(vendor_id: "current_user.vendor_id").order(:name)
end
end
下面是单击向下箭头时模态框的外观图片:
这里是users_controller.rb
中的destroy方法def destroy
# check for vendor manager
@user = User.find(params[:id])
@vendor = @user.vendor
if (@user.id != @vendor.user_manager_id) && params[:user_id].present?
@user.move_data_to_user(params[:user_id])
@user.destroy
flash[:success] = "User removed."
redirect_to users_url
else
redirect_to users_url, notice: "Cannot delete this user."
end
end
这里是模型中的move_data_to_user方法user.rb
def move_data_to_user(new_user_id)
@new_user = User.find_by_id(new_user_id)
self.articles.each { |a| a.user_id = new_user_id ; a.save }
self.audits.update_all(user_id: nil)
self.projects.each do |project|
Audit.create(class_kind: "project", item_id: project.id, action: "unassigned", new_value: self.name, user_id: User.current_user.id, project_id: project.id)
Audit.create(class_kind: "project", item_id: project.id, action: "assigned", new_value: @new_user.name, user_id: User.current_user.id, project_id: project.id) unless @new_user.nil?
end
self.projects.update_all(user_id: new_user_id, vendor_id: self.vendor_id)
self.verified_projects.update_all(user_verified_id: new_user_id)
self.pending_projects.update_all(user_submitted_id: new_user_id)
@new_user.touch
end
这里是全貌show.html.haml:
- provide(:title, @user.name + " - Profile")
.container-fluid
#pad-wrapper.user-profile
// header
.row-fluid.header
.span8
%h3.name{style: "float:none;"}= @user.name
%span.area #{@user.projects.count} projects
- if can?(:destroy, @user) && (@user.id != @vendor.user_manager_id)
= link_to "#", type: "button", id: "user-delete-shortcut", class: "btn btn-danger icon pull-right delete-user", data: { backdrop: "static", toggle: "modal", target: "#user-delete-modal" } do
%i.icon-trash
#user-delete-modal.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "user-delete-modal", :role => "dialog", :tabindex => "-1"}
.modal-header.clearfix
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
%h3#UserDeleteModal Delete User
.modal-body
.row-fluid
.span12
.alert.alert-warning
%strong
In order to remove this user, you must first reassign their projects to another employee.
.row-fluid
.span6.offset3.center
= simple_form_for @user, :html => { :method => :delete } do |f|
= select_tag :user_id, options_from_collection_for_select(users_when_being_deleted(@user), "id", "name")
%br/
%br/
= f.submit "Move Projects & Destroy User", class: 'btn btn-danger center', data: { confirm: 'Are you sure? This cannot be undone!' }
.modal-footer
%ul.step_nav
%li.next
/ = f.submit class: "btn btn-success", name: "Confirm Delete User", value: "Save"
%li.previous
%button.btn.btn-danger{"aria-hidden" => "true", "data-dismiss" => "modal"} Close
- if can?(:edit, @user)
%a.btn.icon.btn-info.pull-right.large.edit{href: edit_user_path(@user)}
%i.icon-edit
Edit #{@user.name}
.row-fluid.profile
.span9.bio
.row-fluid
.span12
.profile-box
- if @recent_projects.any?
.span6
%h6 Recent projects
%br/
.span6
.span{style: 'padding-right: 10px;'}
= will_paginate(@recent_projects, param_name: 'project_page')
// projects table
.table-projects{style: "font-size: 15px;"}
.row-fluid
%table.table.table-hover
%thead
%tr
%th.span3
Name
%th.span3.hidden-phone
%span.line
Assessment
%th.span3.hidden-phone
%span.line
Datalogs
%th.span3.hidden-phone
%span.line
Pictures
%th.span3
%span.line
Status
%th.span3
%span.line
Created
%tbody
- cache ["v1", @recent_projects] do
= render @recent_projects
- else
%h5.center This user doesn't have any projects yet.
// Disabled notes, can reenable if use arrises
/ .span12.section.comment
/ %h6 Add a quick note
/ %p Add a note about this user to keep a history of your interactions.
/ %textarea
/ .span12.submit-box.pull-right
/ %input.btn-glow.primary{:type => "submit", :value => "Add Note"}/
/ %span OR
/ %input.reset{:type => "reset", :value => "Cancel"}/
.row-fluid
.profile-box
.span12
%h6
%i.icon-star
Wishes
%br/
.row-fluid
-if @wishes.any?
%table.table.table-hover
%thead
%tr
%th.span12
Wish
%th.span3
%span.line
Date
%th.span3
%span.line
Browser
%th.span3{colspan: 3}
%span.line
Status
%tbody
- @wishes.each do |wish|
= render "user_wishes", wish: wish
-else
.center
%h4
%i.icon-info-sign
No wishes have been submitted yet.
%br
%br
.row-fluid
.profile-box
- if @audits.any?
.span6
%h6 Recent Audits
%br/
.span6
.span{style: 'padding-right: 10px;'}
= will_paginate(@audits, param_name: 'audit_page')
// audits table
.table-audits{style: "font-size: 15px;"}
.row-fluid
%table.table.table-hover
%thead
%tr
%th.span3
Timestamp
%th.span3.hidden-phone
%span.line
User
%th.span3.hidden-phone
%span.line
Action
%th.span3.hidden-phone
%span.line
Section
%th.span3.hidden-phone
%span.line
Details
%tbody
- cache ["v1", @audits] do
= render @audits
- else
%h5.center This user doesn't have any projects yet.
// Disabled notes, can reenable if use arrises
/ .span12.section.comment
/ %h6 Add a quick note
/ %p Add a note about this user to keep a history of your interactions.
/ %textarea
/ .span12.submit-box.pull-right
/ %input.btn-glow.primary{:type => "submit", :value => "Add Note"}/
/ %span OR
/ %input.reset{:type => "reset", :value => "Cancel"}/
// side column
.span3.address.pull-right
.row-fluid
%h6.center User Details
#user-more-information.row-fluid.center
.span6
%dl
%dt Vendor
%dd= @user.vendor.name
%dt Role
%dd= @user.role.titleize
%dt Member Since
%dd= @user.created_at.strftime("%B #{@user.created_at.day.ordinalize}, %Y")
.span6
%dl
%dt Last Logged In
%dd= @user.last_sign_in_at ? @user.last_sign_in_at.strftime("%m/%d/%Y") : "Never"
%dt Current IP
%dd= @user.current_sign_in_ip
%dt Last IP
%dd= @user.last_sign_in_ip
.row-fluid.center.section
%h6 Project Stats
#user-project-stats
.span6
%dl
%dt Total
%dd= @user.projects.count
.span6
%dl
%dt Incomplete
%dd= @user.projects.incomplete.count
%dt Prepared
%dd= @user.projects.prepared.count
%dt Pending
%dd= @user.projects.pending.count
%dt Verified
%dd= @user.projects.verified.count
.row-fluid
.span2
= link_to 'Back', vendor_users_path(@user.vendor_id), class: 'btn'
如果有其他人想看什么,请告诉我。我不相信在 bootstrap 模态之外还有任何单独的 JavaScript 在起作用。其他一切都很好。我在控制台中没有收到任何关于任何错误的信息,Rails 控制台中也没有任何错误,就好像一旦进入该模态就没有任何事情发生。我被难住了。
如有任何帮助,我们将不胜感激! 感谢您的时间, 斯科特
我认为问题出在查询上。
改变
User.where(vendor_id: "current_user.vendor_id")
到
User.where(vendor_id: current_user.vendor_id)