问题标签 [hanami]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
942 浏览

hanami - 与 Hanami 实现多对多(和其他)关系

我在文档中搜索了如何实现实体之间的关系(例如,一对多、多对多等),但没有找到任何示例。

所以我尝试了一个合理的猜测。这是我尝试实现Person可以​​用Tags 标记的对象:

这在load!通话中失败,并出现以下错误:

在 Hanami 中实现关系的正确方法是什么?

0 投票
1 回答
440 浏览

hanami - 在 Hanami 中实现表单对象

在 Bob 大叔的简洁架构中,Hanami 的灵感来自于此,Form Objects 保护了交互器和我们的交付机制(通常是一个 http 端点)之间的边界。

在 Hanami 文档中,边界守卫是使用paramsActions 中的块完成的(请参阅此处)。这似乎将验证与 http 传递机制相结合。在我看来,Form Objects(或完成同样事情的黑色参数)将存在于与交付机制无关的交互器中,这似乎更自然。

不幸的是,我不知道 Hanami 是否支持这样的设计。我在花见论坛上发现了一个类似的问题,但没有答案。

为了澄清,下面是一段代码,展示了我想做的事情,但使用VirtusActiveModel::Validations不是 Hanami 设施。对于熟悉 Trailblazer 的人来说,它contract在操作中的块(它的术语为交互器)是另一个例子。

最后,我是否误解了 Hanami 的预期用途?Hanami 支持 Interactors,所以看起来这应该是可能的......

0 投票
1 回答
197 浏览

ruby - 为 Web 应用程序的所有用户生成密码

我正在用 ruby​​ 和 hanami 构建一个应用程序,但是我认为我的问题可能与框架无关。该应用程序的用户将登录以预约会议。用户的密码将使用 bcrypt 加密。

我的问题是关于用户创建的。用户不会注册,但他们将由管理员预先创建。所有用户数据都已经是 csv 格式,并且可以直接导入到数据库中,无需管理员单独创建每个数据。

是否可以这样做,并且在导入其余数据后还为所有用户生成密码(如初始密码)?

问候

塞巴

0 投票
2 回答
253 浏览

sql - implement a booking lock for users in a scheduling app

I've built a scheduling web app where users can book a conference for a given date and time slot on that date.

Now I need to implement a booking lock, which means that the admin can apply this lock and users can no longer book from that time on.

My current design includes a model booking_lock that only has one attribute of "status" with values of "On" and "Off".

The model would have only one record in the database at any given time as its sole responsibility would be to provide the data to check if booking has been locked.

---------------------EDIT-----------------------------------

This is not meant to lock individual records (conferences). To do this I use the attribute of user_id. If that is 0, then the conference is available for booking.

What I want to do now is disable (lock) the booking entirely before the user hits the database.

For example:

When a user logs on they see a notification saying the booking is locked. Also, they wouldn't see a respective button to book a conference and if by chance they would navigate to the respective URL they would be redirected to home page with the same notice as above. I've got all this covered.

But I need a general switch to be turned on and off and be the basis for this kind of check. Hence the booking_lock model.

Note: I use hanami-model.

---------------------EDIT-----------------------------------

My question is twofold:

  1. Is there a better way of implementing such a lock?
  2. How to ensure there is only one record in the db for such lock?
0 投票
2 回答
1085 浏览

ruby - Accessing Hash Value in Test

I'm following a Hanami tutorial and I can't work out what's going wrong in this test:

rake test results in a failure because "Confident Ruby" does not equal nil.

I can puts params[:book] after the action.call, but sure enough params[:book][:title] is nil. I've tried to access title via other means but can't seem to manage it. It does seem though that params[:book][:title] should be correct.

However, when I use params[:book]['title'], it appears to work. If I try to create a params hash in IRB, params[:book][:title] works, and params[:book]['title'] doesn't, so I remain confused.

I have upgraded to Ruby 2.3.0, but still experience the same behaviour.

params[:book].has_key?(:title) is false, params[:book].has_key?('title') is true. Cross-referencing with the documentation on how to access hash elements, I just don't get it.

What is happening here?

0 投票
3 回答
204 浏览

ruby - Hanami link_to 助手只渲染最后一个元素

我是花见世界的新手。我写了这段代码:

title我在模板上调用方法。html结果是:

为什么第二个链接会覆盖第一个?我的错误在哪里?

感谢您的任何回复。

0 投票
3 回答
802 浏览

ruby - NoMethodError:Hanami 中带有自定义模块的字符串的未定义方法

我正在使用 Hanami,并在/lib/supports/utils.rb中创建了一个自定义模块。我要求/lib/myapp中的/lib/supports中的所有文件如下所示:

/lib/supports/utils.rb,我有:

我试图将MyModule::Utils::Slug包含在存储库中,但它总是返回NoMethodError: undefined method `slug_it' for "string":String。一个例子:

仅当我在/lib/supports/utils.rb底部添加时才有效:

我想总是像include Hanami::RepositoryEventRepository 一样包含模块。

我究竟做错了什么?

0 投票
1 回答
162 浏览

ruby - 陈旧资产 - Hanami 不更新编辑的文件

我使用 Hanami 和 sass 作为预处理器,但是当我在某些 .scss 文件中进行更改并刷新页面时,更改不会加载,公共/资产/文件.css没有更新。为了更新,我必须删除文件...

有谁知道为什么会这样?

宝石文件

应用程序.rb

0 投票
2 回答
576 浏览

ruby - 如何使用 Hanami/Repository 访问多个数据库

我有一个必须从数据仓库生成报告的应用程序。
我不想将应用程序特定数据(用户、权限、报告定义等)保存在仓库所在的同一数据库中。此外,将来我很可能还必须访问其他数据库(甚至可能是 Oracle)。
我已经在 .env 文件中配置了我的数据库连接,但我不知道是否或在哪里可以定义新连接,也不知道如何为这个显式连接实例化存储库。
由于这是我的应用程序中的第二个容器,我想知道当 hanami-model 不适合我的需要时是否可以更改一个容器的 orm ......

0 投票
0 回答
247 浏览

ruby - 通过 nginx 将 ember 与 api 服务器连接

我有一个 nginx 代理服务器,将 api 服务器连接到我的 ember 客户端。这工作没有任何问题。
但是当我点击刷新按钮时,除了根路由之外的任何路由,浏览器都会点击代理并尝试提供指定的 url。例如,myapp.com/user 在代理服务器中点击用户路由,我得到响应未找到 404。
我对 nginx 很陌生,所以我不完全知道如何配置此设置。这是我的代理配置:

api 服务器是一个 ruby​​/hanami 应用程序。但这没有问题,所以我认为我不必重新配置它。
也许这很重要:我们使用 ember simple auth 进行身份验证。