Rails:通过 link 更新用户
Rails: Update users via link
我正在尝试通过 link 在我看来更新设计记录。
这是我拥有的:
= link_to "Update", user_registration_path(current_user, user: {abc: true}), method: :put, remote: true
我遇到以下问题:
private method `to_param' called for #
如何远程更新此记录?
当我尝试这样做时,我所做的是创建一个 link 解析为喜欢的方法
路线
resources :users do
match "update_abc" => "update_abc#users", :as => :update_abc, via: :get
end
现在在你看来你可以做
users_update_abc_path(current_user, abc: true, efg: 21)
在控制器中
def update_abc
user = user.find(params[:id])
if params[:abc].present?
user.abc = params[:abc]
end
....
user.save
redirect_to :back
end
希望对您有所帮助:)
我正在尝试通过 link 在我看来更新设计记录。
这是我拥有的:
= link_to "Update", user_registration_path(current_user, user: {abc: true}), method: :put, remote: true
我遇到以下问题:
private method `to_param' called for #
如何远程更新此记录?
当我尝试这样做时,我所做的是创建一个 link 解析为喜欢的方法
路线
resources :users do
match "update_abc" => "update_abc#users", :as => :update_abc, via: :get
end
现在在你看来你可以做
users_update_abc_path(current_user, abc: true, efg: 21)
在控制器中
def update_abc
user = user.find(params[:id])
if params[:abc].present?
user.abc = params[:abc]
end
....
user.save
redirect_to :back
end
希望对您有所帮助:)