Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 12:06
    waiting-for-dev synchronize #1197
  • 12:06

    waiting-for-dev on robust_setup

    Make the setup of Hanami more r… (compare)

  • 11:57
    waiting-for-dev commented #1197
  • 11:54
    waiting-for-dev edited #1197
  • 11:54
    waiting-for-dev opened #1197
  • 11:50

    waiting-for-dev on robust_setup

    Make the setup of Hanami more r… (compare)

  • 11:42

    waiting-for-dev on robust_setup

    Make the setup of Hanami more r… (compare)

  • 11:22

    waiting-for-dev on robust_setup

    Make the setup of Hanami more r… (compare)

  • 11:07

    waiting-for-dev on robust_setup

    Make the setup of Hanami more r… (compare)

  • 10:52
    richiesuper starred hanami/hanami
  • 09:50
    depfu[bot] labeled #1196
  • 09:50
    depfu[bot] opened #1196
  • 08:45

    depfu[bot] on check

    Pin dry-core to version 0.8.1 (compare)

  • 08:19
    noraj starred hanami/hanami
  • Aug 11 21:19
    cllns assigned #1192
  • Aug 11 21:19
    cllns closed #1192
  • Aug 11 21:19
    cllns commented #1192
  • Aug 10 16:14
    rustamli starred hanami/hanami
  • Aug 10 13:43
    dmitrylitmanovich starred hanami/hanami
  • Aug 09 12:15
    tomasmuller starred hanami/validations
Aestimo
@iamaestimo
Hey Hanami Devs, am using the hanami 2 template to create an app and when I try to create migrations hanamin db create_migration create_users I keep getting the error below...what am I missing?
Traceback (most recent call last):
    23: from /home/aes/.rbenv/versions/2.7.2/bin/hanami:23:in `<main>'
    22: from /home/aes/.rbenv/versions/2.7.2/bin/hanami:23:in `load'
    21: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/exe/hanami:10:in `<top (required)>'
    20: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-cli-0.7.0/lib/dry/cli.rb:65:in `call'
    19: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-cli-0.7.0/lib/dry/cli.rb:116:in `perform_registry'
    18: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/lib/hanami/cli/commands/application.rb:15:in `call'
    17: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/lib/hanami/cli/commands/monolith/db/create_migration.rb:17:in `call'
    16: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/lib/hanami/cli/commands/application.rb:54:in `database'
    15: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/lib/hanami/cli/commands/application.rb:28:in `application'
    14: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hanami-cli-2.0.0.alpha3/lib/hanami/cli/commands/application.rb:28:in `require'
    13: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/hanami-5998b4f58d84/lib/hanami/init.rb:3:in `<top (required)>'
    12: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/hanami-5998b4f58d84/lib/hanami/init.rb:3:in `require_relative'
    11: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/hanami-5998b4f58d84/lib/hanami/setup.rb:7:in `<top (required)>'
    10: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require'
     9: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require'
     8: from /home/aes/Coding/Ruby/HANAMI/hanami_2_auth_app/config/application.rb:11:in `<top (required)>'
     7: from /home/aes/Coding/Ruby/HANAMI/hanami_2_auth_app/config/application.rb:12:in `<module:Hanami2AuthApp>'
     6: from /home/aes/Coding/Ruby/HANAMI/hanami_2_auth_app/config/application.rb:15:in `<class:Application>'
     5: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/hanami-5998b4f58d84/lib/hanami/application/settings.rb:82:in `method_missing'
     4: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-configurable-0.13.0/lib/dry/configurable/config.rb:112:in `method_missing'
     3: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-configurable-0.13.0/lib/dry/configurable/setting.rb:79:in `value'
     2: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-configurable-0.13.0/lib/dry/configurable/setting.rb:147:in `evaluate'
     1: from /home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-types-1.5.1/lib/dry/types/type.rb:49:in `call'
/home/aes/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dry-types-1.5.1/lib/dry/types/constrained.rb:42:in `call_unsafe': nil violates constraints (type?(String, nil) failed) (Dry::Types::ConstraintError)
2 replies
postmodern
@postmodern:matrix.org
[m]
@warbot: looks like hanami 2.0.0.alpha4 clarified the postgresql:// support: https://hanamirb.org/blog/2021/12/07/announcing-hanami-200alpha4/
1 reply
postmodern
@postmodern:matrix.org
[m]
does Hanami validate the String in container['interactors.interactor_name']? What if I typo the container name, when will Hanami catch that?
1 reply
Seb Wilgosz
@swilgosz

Hi everyone, I've written a JWT authorization gem build on top of dry to easily integrate with Hanami 2.0. https://discourse.hanamirb.org/t/authentication-and-authorization-recommendations/200/6?u=swilgosz

Feel free to check it out! A cool thing is that it uses dry-effects! :D

Sebastjan Hribar
@sebastjan-hribar
Hi all, I'm again out of my comfort zone with trying to determine the best index method for our DB. Here is a SO question with two answers where the first one basically had me doubting I'm doing it right :(
postmodern
@postmodern:matrix.org
[m]
is thre a tutorial on how to setup a basic app with users and authentication?
Seb Wilgosz
@swilgosz
@postmodern:matrix.org I don't think so. It's on my roadmap to be tackled very soon though!
Sebastjan Hribar
@sebastjan-hribar
@postmodern:matrix.org I've written a post how I do it. Not a tutorial for setting up a hanami app, but rather how to use Tachiban. https://sebastjan-hribar.github.io/programming/2021/09/03/tachiban-with-hanami.html
Seb Wilgosz
@swilgosz
@sebastjan-hribar this post is about Hanami 1.x integrqtion though, isn't it?
Sebastjan Hribar
@sebastjan-hribar
@swilgosz true, 1.3 actually. I'm finally able to write a post about authorization with rokku for 1.3 as well. Then I'll move to 2.0 for both gems. Any help for 2.0 is much appreciated :)
postmodern
@postmodern:matrix.org
[m]
Appears Gitter.im is down. Wondering if that's going to cause projects to consider moving to Discord, Element, or Slack?
erthad
@erthad:matrix.org
[m]
Hi, where do partials take context from? What I need exactly is iterate over an array in a template and use partial to render the individual element with context inside that cycle. How do I do that? I didn't find any references to that in docs but only to using partials on their own.
erthad
@erthad:matrix.org
[m]
How do I get the id for foreign key without calling find on that association? I have video belong to location. If I call video.find(id) I get both .location and .location_id to be nil and I can't do a consecutive location.find because of that. How do I do this?
1 reply
I don't use aggregated call for that because I need to extract info from 2 associations and apparently you can't do 2 calls like aggregate(:location).where(id: id).map_to(Video).one in a single call — one of them doesn't seem to update parent object. or am I doing something wrong with this?
class VideoRepository < Hanami::Repository
  associations do
    belongs_to :location
    has_one :video_info
  end

  def find_with_location(id)
    aggregate(:location).where(id: id).map_to(Video).one
  end

  def find_with_info(id)
    aggregate(:video_info).where(id: id).map_to(Video).one
  end

  def find_with_info_and_location(id)   # this function doesn't populate location nor location_id
    aggregate(:location).where(id: id).map_to(Video).one
    aggregate(:video_info).where(id: id).map_to(Video).one
  end
end

Hanami::Model.migration do
  change do
    create_table :videos do
      primary_key :id

      foreign_key :location_id, :locations, null: false
    end
  end
end

Hanami::Model.migration do
  change do
    create_table :locations do
      primary_key :id
    end
  end
end

Hanami::Model.migration do
  change do
    create_table :video_infos do
      primary_key :id

      foreign_key :video_id, :videos, null: false, on_delete: :cascade
    end
  end
end
glemin5011
@glemin5011

Hi everyone, first time here and with a question! I am trying to integrate Webpack (with Babel) for react using the hanami-webpack and hanami-assets gem, but I got into some trouble with import statements.

In my application.html.erb file, i use the <%= javascript 'index' %> helper that points to my index.js file in assets, which works fine when it's pure Javascript and does not have any import statements. However, when i try to import React, it throws an error: "Uncaught SyntaxError: Cannot use import statement outside a module"

One of the solutions i found online is to put "type"="module" to package.json to ensure that all .js files are seen as modules and not CommonJS - I tried doing it, but it lead to another error with my Webpack.config.js file, which is using 'require' instead of import. I changed the file extension to Webpack.config.cjs, which resolved the error the server was throwing, but I am still stuck with 'Cannot use import statement outside of module'

Does anyone know how to solve this? Is there a good example of how to integrate React with Hanami? Thanks!

3 replies
glemin5011
@glemin5011

Hey everyone, hope you are enjoying your holidays - just fyi, after several days of tinkering with trying to integrate React as the frontend with Hanami, I came up with a basic setup that I am hoping is useful to see for anyone who is new and would like to do the same thing - I gave up on Webpack because it was unnecessarily complicated, could not get hot reload to work and the compile times were pretty long - so I used ESbuild instead. Here is a repo with a template you can use: https://github.com/glemin5011/react_on_hanami

Just be aware that it does not have any installer or anything, so things such as .env files etc. are not really transferrable to new projects - this repo is more of a demo / guide

Edit: This is for Hanami v1.3.5

Sebastjan Hribar
@sebastjan-hribar

Hey, I have this code in the views/application.rb:

def current_user_roles
      UserRepository.new.find(session[:current_user]).roles
 end

where the current_user is the user's ID. However, the view has no access to the session. How can I bypass this? The use case is limiting the displayed items as per user roles.

Sebastjan Hribar
@sebastjan-hribar
RE my question above: apps\web\views\application_layout.rb has access to session and other apps like apps\myApp\views\application_layout.rb don't. Why is that?
Sebastjan Hribar
@sebastjan-hribar
I've fixed it my making a helper module accessible to all top views.
Sebastjan Hribar
@sebastjan-hribar
I've just released Rokku 0.7.0. We found a bug when using policies for controllers with the same name. This is now fixed. I've also prepared a short blog post on the use with Hanami 1.3.
Daniel Mircea
@viseztrance
Hi. Could anyone give me a rough estimate of when we'll see version 2 beta / rc released? I'm sure this gets asked a lot but I didn't find any timetable aside from a trello board.
2 replies
Aestimo
@iamaestimo
Is anyone having an issue running bundle when working with the hanami 2 template...for some reason, mine is stuck and does not process beyond this point (ongoing now for over half an hour)
...
Running bundle install - this may take a few minutes
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/hanami/hanami.git
`
Aestimo
@iamaestimo

Hey Hanami experts, I've just cloned the template repo for Hanami 2, followed the steps for setting up, but when it came time to setup a new migration, I ran into the following error:

`method_missing': undefined method `session_secret' for #<Hanami::Application::Settings:0x000055af322964b8 @config=#<Dry::Configurable::Config values={}>> (NoMethodError)

What could I be doing wrong?

Hey Hanami experts, I've just cloned the template repo for Hanami 2, followed the steps for setting up, but when it came time to setup a new migration, I ran into the following error:

`method_missing': undefined method `session_secret' for #<Hanami::Application::Settings:0x000055af322964b8 @config=#<Dry::Configurable::Config values={}>> (NoMethodError)

What could I be doing wrong?

By the way, I've already setup a secret string in the .env file

5 replies
divjot124
@divjot124
hi,can anyone tell me detail reason why hanami has simple code and uses less memory.need it for proof of concept
2 replies
divjot124
@divjot124
hi,could you all tell me some great features that hanami is missing in comparison to rails.
2 replies
Sebastjan Hribar
@sebastjan-hribar
Hi all, I've just posted a question about deployment and hosting services. I'd really appreciate any advise on the topic.
Sebastjan Hribar
@sebastjan-hribar
Hi, I've enabled logging in production and when I pass the stream option I get this error: /usr/local/bundle/gems/http_router-0.11.2/lib/http_router/request.rb:10: warning: URI.unescape is obsolete.
4 replies
It was already reported by @jodosha: joshbuddy/http_router#44. Can I still use this feature, asking more from a performance point of view. The logs get written ok.
Sebastjan Hribar
@sebastjan-hribar

Hi, I've encountered another issue when deploying to production. I'm deploying with docker on client's server and I have bundle exec hanami assets precompile in my docker compose right before starting the server. However, not all assets are in the publicfolder.

If I run precompile before the build and don't run precompile with compose then I get the Internal Server Error.
If I run precompile in a running container the assets are again not served.

I have the option to serve static assets set to true in my .env.production.
As per usual, what am I doing wrong?

5 replies
Sebastjan Hribar
@sebastjan-hribar
I have another matter to tackle, how do I go about running a raw sql query in my rake task? I need to create a pg extension. I can't do it in my compose file because the DB doesn't exist at that point. So my next thought was a separate rake task.
Sebastjan Hribar
@sebastjan-hribar
I ended up doing this in a migration:
Hanami::Model.migration do
  change do
    execute 'CREATE EXTENSION IF NOT EXISTS "pg_trgm"'
  end
end
Jin Feng Xie
@FLemon
Hi, am wondering any one has experience in migrating project from using hanami::model to ROM(standalone) ?
37 replies
ume-san
@ume-san:matrix.org
[m]
Do you think for which of the following use case Hanami 2.0 alpha 6 can be used?
I am really expecting a lot from Hanami 2.0 and I am willing to use it right now. Do you think I can use it for 4 now?
  1. For a personal use (where service can be stopped for a week)
  2. For a community with known people (where service can be stopped for one day)
  3. For a within-company communication tool (where service can be stopped after work)
  4. For a large community with unknown people (where service can be stopped for a few hours)
  5. For a service to customers (where service should not be stopped)
1 reply
ume-san
@ume-san:matrix.org
[m]
My concern is whether Hanami 2.0 updates are what Hanami 2.0 users can follow. Is there any way for Hanami users to follow API changes and directory structure changes? But some people are already using V2 for production apps, which means my concerns are just concerns.
Sebastjan Hribar
@sebastjan-hribar

Is it possible to have raw sql like this:

  def find_by_segment_match(source_text_for_lookup, source_lang)
    segments
      .read("set pg_trgm.similarity_threshold TO 0.4;
      SELECT *, SIMILARITY(segments.content, '#{source_text_for_lookup}') AS similarity
      FROM segments
      JOIN translation_records
      ON segments.id = translation_records.source_segment_id
      LEFT JOIN segments AS target_segments
      ON translation_records.target_segment_id = target_segments.id
      WHERE segments.language_id = #{source_lang} AND segments.content % '#{source_text_for_lookup}'
      ORDER BY segments.content <-> '#{source_text_for_lookup}';").map_to(Segment)
  end

and to map it to a entity, in my case Segment. I wanted to use raw sql since I have trouble implementing the LEFT JOIN with Hanami.

lovelymono
@lovelymono:matrix.org
[m]
Uhm, hi!
How do you go about installing Hanami 2 using gem?
Brandon Weaver
@baweaver

Ohai. One thing that I was always tempted to try for Rails was making a lighter-weight RuboCop AST code migration tool to automate most of the upgrades for folks.

Would that be of much interest here?

1 reply
Brandon Weaver
@baweaver:matrix.org
[m]
Ok, trying out Matrix instead of a web tab which I'll lose track of.
Brandon Weaver
@baweaver:matrix.org
[m]
(Speaking of, up for any advice on managing n+1 chat apps between Discord, Slack, Matrix, etc etc)
KOW
@kowfm_twitter
Hey friends. Is Hanami suitable for apis? I was pointed to use https://github.com/hanami/api on Twitter but I'm not sure if this is an addon to hanami or a replacement.
9 replies
KOW
@kowfm_twitter
I have a question. How do you reset the database in the test environment? I've run into a situation where subsequent tests written while following the tutorials fail because of a Unique constraint on a table.
1 reply
Sebastjan Hribar
@sebastjan-hribar
Regarding my above question of mapping to another entity, I've posted a bit more detailed use case and problem description here: https://discourse.hanamirb.org/t/complex-joins-and-raw-sql-query-problem/687/2. Could someone check and confirm that I'm doing something wrong or is this an issue to report? In short, I need to map a query result to another entity or a Dry::Struct.
Sebastjan Hribar
@sebastjan-hribar
Just found this workaround: I setup a placeholder entity with a repo and read the raw sql there. It's a prototype so I'll post my answer when I have it fully working.
Paul Sadauskas
@paul
Where does Rack middleware get added in Hanami 2? (specifically omniauth)
1 reply
Joel AZEMAR
@joel
Hi folks! Is there a simple way to get the Guide 2.0 other than through the pending PRs https://github.com/hanami/guides/pulls? Thanks 🙏
Sebastjan Hribar
@sebastjan-hribar

Hi , I've ran this migration, which completed without errors, but when I run the server below:

Hanami::Model.migration do
  change do
    alter_table :segments do
    add_column :ts_content1, :tsvector, generated_always_as: [to_tsvector: [:simple, :content]]
    end
  end
end

Error:

Hanami::Model::Error: missing attributes in ROM::Relation::Name(segments) schema: :ts_content1

How can I debug this?

Sebastjan Hribar
@sebastjan-hribar
Basically, I can't use inferred schema and I can't use custom schema, since tsvector is not supported data type. Any way around this?