具有两个参数的Link_to无法正常工作 [英] Link_to with two parameters not working

查看:59
本文介绍了具有两个参数的Link_to无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在组织的页面上,我有一个局部页面,向该用户显示具有该组织主持人角色的用户.每个用户/主持人后面都有一个链接,用于删除该角色.但是,此链接无效.单击它时,没有任何反应.在浏览器的网址栏中,它仅显示新文本:https://url/organizations/ek99?data[confirm]=Are+you+certain%3F&data[method]=post&data[organization_id]=100&data[stakeholder_id]=113&data[url]=%2Fremovemoderator%2Fek99.有人可能看到这段代码有什么问题吗?

On a page of an organization I have a partial that shows the users with the moderator role for that organization. Behind each user/moderator there's a link to remove that role. However, this link isn't working. When clicking it, nothing happens. In the url bar of the browser it only shows new text: https://url/organizations/ek99?data[confirm]=Are+you+certain%3F&data[method]=post&data[organization_id]=100&data[stakeholder_id]=113&data[url]=%2Fremovemoderator%2Fek99. Does anyone perhaps see what is wrong with this code?

组织控制者中:

def show
  @organization = Organization.friendly.find(params[:id])
  @moderators = User.with_role(:moderator, @organization)
end

视图页面使用<%= render 'users/moderator', collection: @moderators %>调用部分视图. 部分包含每个主持人的链接:

The view page calls on the partial using <%= render 'users/moderator', collection: @moderators %>. The partial contains for each moderator the link:

<%= link_to image_tag("delete.gif", title: "remove as moderator", class: 'profile-icon-small'), 
            data: { user_id: moderator.id, organization_id: @organization.id, method: :post, url: removemoderator_path, confirm: "Are you certain?" } %>

路线:

post 'removemoderator/:id'=>  'users#remove_moderator', as: 'removemoderator'

用户控制器方法:

def remove_moderator
  @organization = Organization.friendly.find(params[:id])
  remove_modrights(@organization)
end

用户模型方法:

def remove_modrights(organization)
  self.remove_role :moderator, organization
end

推荐答案

def remove_moderator 
    @user = User.find(params[:id])
    @organization = Organization.friendly.find(params[:organization_id])
    @user.remove_modrights(@organization)
    redirect_to @organization
end

链接中的网址应包含ID.

The url in link should contain id.

<%= link_to image_tag("delete.gif", title: "remove as moderator", class: 'profile-icon-small'), removemoderator_path(id: moderator.id, organization_id: @organization.id), method: :post, data: { confirm: "Are you certain?" } %>

这篇关于具有两个参数的Link_to无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆