Link_to有两个参数不起作用

时间:2015-06-29 19:24:56

标签: ruby-on-rails ruby ruby-on-rails-4 model-view-controller

在组织的页面上,我有一个部分显示具有该组织的主持人角色的用户。在每个用户/主持人后面都有一个删除该角色的链接。但是,此链接无效。单击它时,没有任何反应。在浏览器的网址栏中,它只显示新文字: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。有没有人可能会看到这段代码有什么问题?

组织控制器

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

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

<%= 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

1 个答案:

答案 0 :(得分:1)

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

链接中的网址应包含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?" } %>