P165 若没有一个用户时弹出注册框

目标是当用户输入:http://localhost:3000/admin时,如果还没有一个管理用户帐号,就自动弹出注册用户帐号的界面。

在全局控制器application.rb中,加入:
  def first_account_create
flash[:notice] = '请新增一个管理用户!'
redirect_to(:controller => "login", :action => "add_user")
end



在控制器:login_controller.rb中,过滤器改为:
  if User.count.zero?
before_filter :first_account_create, :except => :add_user
else
before_filter :authorize, :except => :login
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Vue.js的框组件来实现这个功能。以下是一个简单的示例: 首先,在你的Vue组件中,你需要导入框组件并注册它: ```javascript <template> <div> <button @click="showModal">点击打开框</button> <modal :show="show" @close="closeModal"> <h2>这是一个框</h2> <p>点击外部区域或按钮关闭框</p> </modal> </div> </template> <script> import Modal from './Modal.vue'; export default { components: { Modal }, data() { return { show: false } }, methods: { showModal() { this.show = true; }, closeModal() { this.show = false; } } } </script> ``` 然后,你需要创建一个框组件。这个组件需要接收一个`show`属性来控制框是否显示,以及一个`close`事件来关闭框。 ```javascript <template> <div class="modal-mask" v-if="show"> <div class="modal-wrapper"> <div class="modal-container"> <div class="modal-header"> <slot name="header"></slot> <button class="modal-close-button" @click="$emit('close')">×</button> </div> <div class="modal-body"> <slot></slot> </div> </div> </div> </div> </template> <script> export default { props: { show: Boolean } } </script> <style> .modal-mask { position: fixed; z-index: 9998; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, .5); display: table; transition: opacity .3s ease; } .modal-wrapper { display: table-cell; vertical-align: middle; } .modal-container { width: 300px; margin: 0px auto; padding: 20px 30px; background-color: #fff; border-radius: 2px; box-shadow: 0 2px 8px rgba(0, 0, 0, .33); transition: all .3s ease; font-family: Helvetica, Arial, sans-serif; } .modal-header h3 { margin-top: 0; color: #42b983; } .modal-body { margin: 20px 0; } </style> ``` 最后,在你的CSS文件中,你可以为框添加样式。这个样式只是一个示例,你可以根据自己的需要进行修改。 这就是一个简单的Vue.js框组件。当用户点击按钮框会现。当用户点击外部区域或按钮框会关闭。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值