weixin_33697898 2016-12-25 14:51 采纳率: 0%
浏览 44

Rails:通过链接更新用户

I am trying to update a devise record via a link in my view.

This is what I've have:

= link_to "Update", user_registration_path(current_user, user: {abc: true}), method: :put, remote: true

I get the following issue:

private method `to_param' called for #

How am I able to update this record remotely?

  • 写回答

1条回答 默认 最新

  • weixin_33720452 2016-12-25 15:19
    关注

    When I try to do this what I do is a create a method that the link resolves to like

    routes

    resources :users do 
      match "update_abc" => "update_abc#users", :as => :update_abc, via: :get
    end
    

    now in your view you can do

    users_update_abc_path(current_user, abc: true, efg: 21)
    

    and in the controller

    def update_abc
      user = user.find(params[:id])
      if params[:abc].present?
        user.abc = params[:abc]
      end
      ....
      user.save
      redirect_to :back
    end
    

    I hope that this helps :)

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本