我已经阅读了许多类似的SO帖子,但无法找到解决我在这里的路由错误的帖子。我制作了一个基本的wiki类应用,当用户从premium
降级到standard
时(将user.premium?
的布尔值更改为false
),我想要此操作也会更改所有wikis
的布尔值,因此wiki.private?
为false
。该链接位于devise/registrations/edit.html.erb
页面:
<h3>Change My Account Type</h3>
<% if current_user.premium %>
<p><%= link_to "Downgrade my account from premium.", downgrade_user_path(current_user), confirm: "Are you sure?" %></p>
<% else %>
<p><%= link_to "Upgrade to premium!", new_charge_path %>
<% end %>
这是users_controller
:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@wikis = current_user.wikis
@private_wikis = @wikis.where(private: true)
@public_wikis = @wikis.where(private: false)
end
def downgrade
@wikis = current_user.wikis
@user = User.find(params[:id])
@user.update_attribute(:premium, false)
@wikis.each do |wiki|
wiki.update_attribute(:private, false)
end
end
end
以下是路线:
match "users/:id/downgrade" => "users#downgrade", :as => "downgrade_user", via: [:get, :post]
该操作成功降级了用户,但在尝试将所有私有wikis
公开时,我收到了丢失的模板错误:
Missing template users/downgrade, application/downgrade with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}.
这让我觉得路由出错了。谁能看到我在这里出错的地方?
答案 0 :(得分:0)
在完成降级用户的所有业务逻辑之后,您想做什么?
def downgrade
@wikis = current_user.wikis
@user = User.find(params[:id])
@user.update_attribute(:premium, false)
@wikis.each do |wiki|
wiki.update_attribute(:private, false)
end
redirect_to user_registration_path
end