gpt4 book ai didi

ruby-on-rails - 控制台和 View 之间的不同值

转载 作者:太空宇宙 更新时间:2023-11-03 18:04:16 27 4
gpt4 key购买 nike

我有一个我不明白的“wtf”问题。我有一个 View ,用户可以在其中看到他的所有图片。在每张图片上,都有一个删除图片的图标。此图标打开一个模式,其中有一个删除图片的链接。但是每个链接都会删除 View 中的第一张图片。

最奇怪的是:

= picture_path(picture)
# => path of the first picture

- puts picture_path(picture)
# => path of the right picture

这怎么可能?

这是我的部分观点:

_gallery.slim

.row
- pictures.each do |picture|
.col-xs-10.col-xs-offset-1.col-sm-6.col-sm-offset-0.col-md-4.col-lg-3
# Some code
.caption id="pictures-#{picture.id}"
.row
- if current_user == @user
= render 'pictures/form_position', picture: picture # => Here we go

_form_position.slim

.caption-edit.d-block
.col-lg-6.col-md-6.col-xs-6
div
span> Position
span.hide-if-edit
=> picture.position
span.icon.icon-edit.picture-position-icon.hide-if-edit
span.icon.icon-delete.hidden.picture-position-icon.position-form data-toggle= 'modal' data-target= '#delete-picture-modal'
= render 'pictures/destroy_picture_modal', picture: picture # => My modal
.col-lg-6.col-md-6.col-xs-6.position-form.hidden
= simple_form_for picture, remote: true do |f|
= hidden_field_tag(:position)
= f.input :position, wrapper: :vertical_input_group, label: false do
= f.input_field :position, value: picture.position, class: 'form-control'
.input-group-btn
= button_tag type: 'submit', class: 'btn btn-primary' do
i.icon.icon-check

_destroy_picture_modal.slim

.modal.fade#delete-picture-modal tabindex= '-1' role= 'dialog' aria-hidden= 'true'
.modal-dialog role= 'document'
.modal-content
.modal-header
button type="button" class="close" data-dismiss="modal" ×
h5.modal-title Delete the picture
.modal-body
p Are you sure?
.modal-footer
= button_tag 'Cancel', type: 'button', class: 'btn btn-secondary', data: { dismiss: 'modal' }
= link_to picture_path(picture), method: :delete do # => Where there's a problem
= button_tag 'Delete', type: 'button', class: 'btn btn-primary'

我提醒你:

= picture_path(picture)
# => return the path of the first picture

- puts picture_path(picture)
# => return the right path

你看到我的代码有什么问题了吗?

最佳答案

您正在为多个模式使用一个 id 标识符:

data-target= '#delete-picture-modal'

正在呈现多个模态框,但您在单击删除图标时始终针对“第一个”模态框。

您需要为每个模式分配一个唯一的 ID,并相应地定位它。 (或者,通过一些异步 javascript 填充模式。)

关于ruby-on-rails - 控制台和 View 之间的不同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52444522/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com