启用turbo_frame:有条件的模态标签
我有一个用于创建新项目的链接
<li>
<%= link_to "List an item", new_item_path, data: { turbo_frame: 'modal' } %>
</li>
,此链接在turbo_frame_tag modal &lt;%= turbo_frame_tag“ modal”%&gt;
我需要做的是允许用户仅列出3个项目。如果他们单击上面,则将其重定向到root_path,并带有通知。
我在项目控制器中有这样的验证:
before_action :check_limited_items, if: :signed_in?, only: :new
def check_limited_items
limited_items = 3
return unless current_user.items_count == limited_items
redirect_to root_path
flash[:notice] = "Allow 3 items only."
end
当我单击上面的链接以获取新项目时,它无济于事。当我刷新时,会出现闪电通知。
我该如何解决?控制器是验证或模型的好地方吗? 我尝试了同样的结果。
I have a link for creating a new item
<li>
<%= link_to "List an item", new_item_path, data: { turbo_frame: 'modal' } %>
</li>
This opens a item form in a turbo_frame_tag modal <%= turbo_frame_tag "modal" %>
What I need to do is, allow users to list 3 items only. And if they click on above link it redirect it to root_path with a notice.
I have such validation in item controller:
before_action :check_limited_items, if: :signed_in?, only: :new
def check_limited_items
limited_items = 3
return unless current_user.items_count == limited_items
redirect_to root_path
flash[:notice] = "Allow 3 items only."
end
When I click on above link for a new item, it does nothing. When i refresh, flash notice shows up.
How could I fix that? And is a controller a good place for validation or model?
I tried both and same result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论