我目前有一个用户系统设置2个模型 - >计划模型has_many用户。属性不在PUT请求更新
我想实现的是一种允许用户升级/降级计划的方法。为此,我在控制器中创建了一个名为“update_plan”的POST动作,并且当用户向其发布新的Plan_id时,比用户的plan_id更改,因此将订阅不同的计划。
当我POST到更新计划控制器时,虽然用户的plan_id没有更改。我首先要到控制台,并做
user = User.find(1)
user.plan.id
当检查plan_id的数据类型,第二次验证了这一点,没有任何变化。
这里是我的形式看起来像改变计划ID
<%= form_tag("https://stackoverflow.com/users/update_plan", :method => "post") do %>
<%= hidden_field_tag :plan_id, plan.id %>
<%= submit_tag("Change To Plan", :class => "signup") %>
<% end %>
而这里的更新行动计划,在用户控制器
def update_plan
@user = current_user
if @user.update_attributes(params[:plan_id])
flash[:success] = "Profile updated"
sign_in @user
redirect_to change_plan_path
else
render change_plan_path
flash[:errors] = "Oops, something went wrong with the Update. Please Talk To Support"
end
end
我不太清楚错误所在,虽然,因为我在上面写的核心中不太确定。
如何更新用户的plan_id参数?任何帮助极大赞赏
我想你需要做'@ user.update_attributes(params)' – bdares