我在 ruby on rails 中遇到问题。当用户访问/homepage/时,我想让当前用户的商店id为0,当用户访问/homepage/:id/时,我想让用户的商店id成为url中的输入id。
我的代码:
routes.rb:
match "/homepage" => "users#access", :as => "store"
match "/homepage/:id" => "users#homepage", :as => "store"
def access
@user = current_user
@user.update_attributes(:store => "0")
@user.save
end
def homepagestore
@user = current_user
@user.update_attribute(:id, user.store = :id)
@user.save
end