Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 10:45
    baclv starred hanami/hanami
  • 03:33
    richizo starred hanami/hanami
  • Sep 14 17:15

    depfu[bot] on check

    (compare)

  • Sep 14 17:00

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

  • Sep 14 16:55

    depfu[bot] on check

    (compare)

  • Sep 14 15:53

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

  • Sep 14 15:45

    depfu[bot] on check

    (compare)

  • Sep 14 14:40

    depfu[bot] on check

    Pin hanami-validations to versi… (compare)

  • Sep 14 14:35

    depfu[bot] on check

    (compare)

  • Sep 14 13:30

    depfu[bot] on check

    Pin hanami-assets to version 1.… (compare)

  • Sep 14 13:19

    depfu[bot] on check

    (compare)

  • Sep 14 13:10

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

  • Sep 14 12:53

    depfu[bot] on check

    (compare)

  • Sep 14 12:45

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

  • Sep 14 12:40

    depfu[bot] on check

    (compare)

  • Sep 14 12:26
    wade1990 starred hanami/helpers
  • Sep 14 12:26
  • Sep 14 12:25

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

  • Sep 14 12:18

    depfu[bot] on check

    (compare)

  • Sep 14 12:00

    depfu[bot] on check

    Pin hanami-utils to version 1.3… (compare)

Pablo Crivella
@pablocrivella
hmm okay, I would really like Hanami 2 behaviour atm.. working on an app that relies a lot on Exceptions for control flow...currently works fine with the way sinatra handles the exceptions
Having a hard time trying to convince the team to switch gradually from sinatra to hanami :sweat_smile:
Luca Guidi
@jodosha
@pablocrivella Would you share a concrete code example? In a DM, if you prefer. Are you using full stack Hanami?
Maks
@maks_ah_gitlab
@jodosha Hi, thanks for the reply, it works fine indeed. In terminal probably pry just calls to_s before printing it. But the object is correct and I can still use all methods on it :+1:
Luca Guidi
@jodosha
I’m happy you figured out. 💪
Alexander Koval
@k0va1
Hello! Does anyone use http://rocketjob.github.io/semantic_logger/ instead of default Hanami logger? I’ve faced with problem that it hasn’t log http requests, only database queries
Lairan
@alex-lairan

Hey !

I'm using Hanami controller with Rails, and I got a problem with tests.

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Contents::ShowController, type: :request do
  subject(:request) { get "/api/v1/contents/#{content_id}", headers: headers }

  let(:headers) { { CONTENT_TYPE: 'application/json', HTTP_X_TENANT_ID: tenant_id.to_s } }
  let(:tenant) { FactoryBot.create(:tenant) }

  before do
    Tenant.collection.drop
    Content.collection.drop

    FactoryBot.create(:content, :page, id: 'abc', tenant_id: tenant.id)
  end

  context 'with valid content ID' do
    let(:content_id) { 'abc' }

    context 'with valid tenant ID' do
      let(:tenant_id) { tenant.id }

      it { is_expected.to eq(200) }
    end

    context 'with invalid tenant ID' do
      let(:tenant_id) { 'random' }

      it { is_expected.to eq(404) }
    end
  end

  context 'with invalid content ID' do
    let(:content_id) { 'def' }
    let(:tenant_id) { tenant.id }

    it { is_expected.to eq(404) }
  end
end

The headers change everytimes, but the controller keep the 1st headers.

So when the tenant_id changes, the controller keep the old one.

Any idea ?

Lairan
@alex-lairan
params.env['HTTP_X_TENANT_ID'] give me the correct tenant_id
request.env['HTTP_X_TENANT_ID'] give me the old one
Jeff Dickey
@jdickey

Hey, is anyone doing anything with hanami-events? The repo seems to indicate that an 0.2.1 release (and 0.2.0, 0.1.0) have been released, but RubyGems only knows about the (empty) 0.0.0 version. Am I missing something, or can one of the maintainers push the latest to RubyGems? Thanks

In the same vein, what event pub/sub libraries have people used with Hanami?

Luca Guidi
@jodosha
@jdickey AFAIK mr @davydovanton and friends are using it in production since long time, depending on edge version from GH. I'll make sure to understand what's going on over there and let you know.
Luca Guidi
@jodosha
Folks, I'll be away from computers for a month. Ping me for urgent matters. Love you all :green_heart: Ciao! :wave:
Oliynyk Taras
@tarnonero
hello, guys! What is a good way to benchmark hanami performance ? I mena things like requests/sec, memory usage e so on.
Jeff Dickey
@jdickey
Hey, folks, I'm trying to clean up after a bit of a security scare that mostly had the (beneficial) effect of convincing TPTB that yes, even though we're not in Rails any more doesn't mean the automated and/or talented crackers aren't out to mess with us anyway. There's scads of docs out there for hardening Rails apps, along with tools like Brakeman and a dozen others; what are people using/recommending for Hanami apps and/or Docker-based deployments?
Alexander Koval
@k0va1

hi, guys! i'm trying to use hanami helpers and I want to show something like this: <div> text <button></button> </div>. I wrote this code, but it doesn't work

html.div do
  html.text 'text'
  html.button
end

It returns "<div>\n<button></button>\n</div>" without text. WAIDW?

Jeff Dickey
@jdickey
@jodosha Thanks very much for any help. You'd think this should be simpler, and it very likely is; I hope to contribute docs when we get our app up and happy. Thanks again
Alexander Koval
@k0va1
@jodosha any suggestions?
Pablo Crivella
@pablocrivella

Folks, I'll be away from computers for a month. Ping me for urgent matters. Love you all :green_heart: Ciao! :wave:

@k0va1 I think you will have to wait a bit for his reply :sweat_smile:

Alexander Koval
@k0va1
i've figured out recently) you need just to remove html in nested elements
Danny Santos
@DannySantos
I’m having issues with having more than one of the same form on a page. I submit them using AJAX and when the area of the page is re-rendered the params fill in all of the forms with the submitted forms values because they all have the same name attributes. Anyone have any tips for dealing with this?
Edouard
@inouire_twitter
Could you index your form keys ? Like :form_1, :form_2... (with any name you would like).
Danny Santos
@DannySantos
@inouire_twitter I did consider that but is that good practice? Namespacing all of your params? It would also mean handling that in the validations which just doesn’t quite feel right.
Danny Santos
@DannySantos
I figured out that if you specify inline values on the fields as opposed to passing them into form_for then they take precedence over the params values. The issue with this approach is that it won’t do its job of retaining failed form values. It just so happens that the way I’ve implemented this particular form means that this isn’t a problem for me but it seems like a pretty big problem for Hanami in general. Has nobody else come across it?
Edouard
@inouire_twitter
I don't think that it is a "good practice" but at some point if the forms are the same but you dont want them to behave the same there must be some kind of way for the machines to distinguish them.
henriquefernandez
@henriquefernandez
@jodosha
henriquefernandez
@henriquefernandez
Good evening, will be easy to migrate an existing hanami 1.3 app to the 2.0 version?
I need to start a new API project in my work, and we dont want to use Rails. We will do some clean architecture.
We thought to use Hanami because there are some Ruby POROS that we can use from the legacy Rails app. The other option is Elixir / Phoenix.
ivanbokii
@ivanbokii
Hi folks, I've just noticed that all my requests are very slow (dev env) despite server claiming very fast response time in logs. I've posted a question here: https://discourse.hanamirb.org/t/slow-response-time/522
would appreciate your help!
alright, nevermind - didn't know about --no-code-reload
Edouard
@inouire_twitter
@henriquefernandez from what I understood from Lucas video presenting what v2 Will look like, migration will require some work as many things will change. I'd say From a few hours To a couple of days depending on the size of your app.
But apps with hanami are so simple that i don't fear this migration
Sebastian Nowak
@seban
Is there any ETA when 2.0 will be released?
Sebastian Nowak
@seban
or maybe there is any list of issues todo before 2.0 will be ready?
Paweł Świątkowski
@katafrakt
@seban check this https://trello.com/b/lFifnBti/hanami-20, there's no ETA as far as I know
Steven Podlecki
@spodlecki

good morning. I've recently picked up a project that is using Hanami. I'm not sure if I'm just missing something in the documentation, or its just not possible..

All I'm trying to accomplish is - if param validation fails, render template X, if it succeeds, render template Y. Can someone point me in the right direction?

I've looked at hanami source, and the template seems to just be rendering based off a string -- (doesn't use procs as far as I can tell)
Kai Kuchenbecker
@kaikuchn
@spodlecki would a redirect work for you? Otherwise you could either use custom rendering (https://guides.hanamirb.org/views/basic-usage/#custom-rendering) or entirely bypass it.
If you do the latter, I'd suggest to create two views - one for each template - and then call them from the action. See https://github.com/hanami/view#views on how to use a view.
Steven Podlecki
@spodlecki

@kaikuchn a redirect won't - so here's an idea, but I've got a feeling it's going way too deep into the code messing with private methods. Couldn't I overwrite Hanami::View::Rendering#template method with my conditions? Just thinking about it makes me feel odd, mainly because its a private method inside a gem that could easily just change

(feature request: I really think the template method should be able to accept a block w/ the context of the request.)

Kai Kuchenbecker
@kaikuchn
Why not just do one of the other approaches I suggested? E.g., the latter might look like this:
# apps/web/controllers/signup/create.rb
module Web
  module Controllers
    module Signup
      class Create
        include Web::Action

        params do
          required(:name).filled(:str?)
          required(:email).filled(:str?, format?: /@/).confirmation
        end

        def call(params)
          self.body = if params.valid?
                        Web::Views::SignupSuccess.render(format: :html)
                      else
                        Web::Views::SignupFailure.render(format: :html)
                      end
        end
      end
    end
  end
end
If you need params in there, or other exposures, then pass them in as additional keyword arguments
E.g.: Web::Views::SignupSuccess.render(format: :html, user: user)
Steven Podlecki
@spodlecki
I mis-read, I like this solution much better -- what I understood your recommendation to be, was to put the logic inside the View even though now that I re-read, I see you said action.. I think my eye skipped to the link and just thought "view"
Kai Kuchenbecker
@kaikuchn
Ah ok :)
Steven Podlecki
@spodlecki
this was exactly what I was thinking should be possible, this keeps my templates and views nice and dumb -- thank you
Kai Kuchenbecker
@kaikuchn
Glad I could help you out!
hieuk09
@sincepast_twitter

Hello, currently I have a problem when using custom entity with map_to:

class AppConnectionWithDomain < AppConnection
  attributes do
    attribute :id, Types::Int
    attribute :app_domain, Types::String
  end
end

class AppConnectionRepository < Hanami::AppConnectionRepository
  def find_by_domain(domain)
    app_connections.join(:apps, id: :app_id)
      .where(Sequel.lit('apps.domain') => domain)
      .select { [id, `apps.domain`.as(:app_domain)] }
      .map_to(AppConnectionWithDomain)
      .first
  end
end

In this case, repository.find_by_domain(domain) returns AppConnection entity instead of the custom AppConnectionWithDomain entity. My current fix is using map with to_h, but I wonder if there are any other solutions for this?

glaszig
@glaszig
hello folks. i have a static page action that renders a show.html.erb template which renders a partial based upon the url the user requests. now, if a user accesses a page that does not exist, i want hanami to render a 404. but even with handle_exception Hanami::View::MissingTemplateError => 404 it gives a 505. any idea?
glaszig
@glaszig
oh nice. i cannot catch MissingTemplateError as part of hanami-controller's error handling because that one is being raised only after the action has already been called. and it happens in Hanami::RenderingPolicy. ;(
Greg
@greggilbert
Hey all - I find my app sometimes getting stuck in this loop where users keep getting InvalidCSRF errors. I think it has to do with visiting the site from www and non-www. Any idea why that happens? Something about mixing the session secrets?
glaszig
@glaszig
@greggilbert the csrf token is stored in a session. the session is, by default, stored in a cookie. now, if you visit www.example.com, that session cookie is only valid for that subdomain -- not the example.com apex domain. i would try setting the cookie domain to example.com explicitly. that way, it'll always be set for that domain. i don't know, though, if browser's tracking protection interfers there.
# application.rb
module Example
  class Application < Hanami::Application
    configure do
      sessions :cookie, secret: "...", key: "...", domain: "example.com"
    end
  end
end