解决link_to 中delete无效的问题

本文记录了解决Rails应用中删除功能问题的过程,包括引入jQuery文件、配置预编译资源、解决认证令牌错误及调整控制器逻辑等步骤。

原文链接

照着RubyGuide里面敲一遍,前面的还好,直到遇到D:destroy 出问题了。

问题代码: 

<td><%= link_to 'Destroy', article_path(article),:method => :delete,data: { confirm: 'Are you sure?' } %></td>

首先, 点击 删除 链接之后,跳到了show页面,完全没有弹出框提示,

原因:jquery的js文件没有引入

解决方法:app/view/layouts/application.html.erb 添加

<%= javascript_include_tag "jquery.min" %>  //链接js文件
<%= javascript_include_tag "jquery_ujs" %>
 然后报错:

Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( jquery.min.js )` to `config/initializers/assets.rb` and restart your server
解决方法:按照提示添加即可

重启,可以弹出窗口了,确定,报错:

ActionController::InvalidAuthenticityToken

解决方法:app/view/layouts/application.html.erb 添加

然后发现跳转还是有问题,

更改articles_controller.rb里面的destroy方法

def destroy
		@article=Article.find(params[:id])
		@article.destroy
		redirect_to articles_path

	end

<%= csrf_meta_tag %>


再次尝试,删除成功!





static int ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_bss_conf *link_conf, struct ieee80211_chanctx_conf *ctx) { struct ath12k_hw *ah = ath12k_hw_to_ah(hw); struct ath12k *ar; struct ath12k_base *ab; struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); u8 link_id = link_conf->link_id; struct ath12k_link_vif *arvif; int ret; lockdep_assert_wiphy(hw->wiphy); /* For multi radio wiphy, the vdev was not created during add_interface * create now since we have a channel ctx now to assign to a specific ar/fw */ arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); if (!arvif) { WARN_ON(1); return -ENOMEM; } ar = ath12k_mac_assign_vif_to_vdev(hw, arvif, ctx); if (!ar) { ath12k_hw_warn(ah, "failed to assign chanctx for vif %pM link id %u link vif is already started", vif->addr, link_id); return -EINVAL; } ab = ar->ab; ath12k_dbg(ab, ATH12K_DBG_MAC, "mac chanctx assign ptr %p vdev_id %i\n", ctx, arvif->vdev_id); if (ath12k_wmi_supports_6ghz_cc_ext(ar) && ctx->def.chan->band == NL80211_BAND_6GHZ && ahvif->vdev_type == WMI_VDEV_TYPE_STA) ath12k_mac_parse_tx_pwr_env(ar, arvif); arvif->punct_bitmap = ctx->def.punctured; /* for some targets bss peer must be created before vdev_start */ if (ab->hw_params->vdev_start_delay && ahvif->vdev_type != WMI_VDEV_TYPE_AP && ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR && !ath12k_peer_exist_by_vdev_id(ab, arvif->vdev_id)) { ret = 0; goto out; } if (WARN_ON(arvif->is_started)) { ret = -EBUSY; goto out; } if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { ret = ath12k_mac_monitor_start(ar); if (ret) { ath12k_mac_monitor_vdev_delete(ar); goto out; } arvif->is_started = true; goto out; } ret = ath12k_mac_vdev_start(arvif, ctx); if (ret) { ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", arvif->vdev_id, vif->addr, ctx->def.chan->center_freq, ret); goto out; } arvif->is_started = true; /* TODO: Setup ps and cts/rts protection */ out: return ret; }这个函数的作用
09-19
Linux进程控制第1关本关的编程任务是补全右侧代码片段以下几个部分: create_linkfile5_sl 函数主体部分Begin至End中间的代码 delete_linkfile5_sl 函数主体部分Begin至End中间的代码 create_linkfile6_sl 函数主体部分Begin至End中间的代码 delete_linkfile6_sl 函数主体部分Begin至End中间的代码 具体要求如下: 函数create_linkfile5_sl检查./file5文件是否存在,如果存在则创建软链接文件./file5_sl,然后返回 0 。如果不存在,则返回 -1; 函数delete_linkfile5_sl检查./file5_sl文件是否存在,如果存在则删除linkfile5_sl,然后返回 0 。如果不存在此文件,则返回 -1; 函数create_linkfile6_sl检查./file6文件是否存在,如果存在则创建软链接文件1./file6_sl1,然后返回 0 。如果不存在,则返回 -1; 函数 1delete _linkfile6_sl1检查1./file6_sl1文件是否存在,如果存在则删除 1linkfile6 _sl1,然后返回 0 。如果不存在此文件,则返回-1; 本关涉及的代码文件ChmodDamon.c的代码框架如下: #include <unistd.h> int create_linkfile5_sl(const char*newfile) { int ret = -1; /********** Begin *********/ /********** End *********/ return ret; } int delete_linkfile5_sl(const char*filename) { int ret = -1; /********** Begin *********/ /********** End *********/ return ret; } int create_linkfile6_sl(const char*newfile) { int ret = -1; /********** Begin *********/ /********** End *********/ r:进程等待
04-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值