Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 03:03
    itopmoon starred hanami/hanami
  • Sep 22 04:30
    HoangNguyen679 starred hanami/hanami
  • Sep 21 17:23
    Kushal334 starred hanami/hanami
  • Sep 17 13:13
    timriley synchronize #1123
  • Sep 17 13:13

    timriley on elide-slice-name-in-lib

    Elide slice name from lib/ when… (compare)

  • Sep 17 13:11
    timriley opened #1123
  • Sep 17 13:09

    timriley on elide-slice-name-in-lib

    Elide slice name from lib/ when… (compare)

  • Sep 17 03:08
    redvoilin starred hanami/hanami
  • Sep 16 00:49
    woarewe starred hanami/router
  • Sep 15 07:33
    BulatKarimov starred hanami/hanami
  • Sep 14 17:14
    kotx starred hanami/hanami
  • Sep 14 17:05

    depfu[bot] on update

    (compare)

  • Sep 14 17:05
    depfu[bot] closed #648
  • Sep 14 17:05
    depfu[bot] commented #648
  • Sep 14 17:05
    depfu[bot] labeled #649
  • Sep 14 17:05
    depfu[bot] opened #649
  • Sep 14 16:00

    depfu[bot] on update

    Update rubocop to version 1.21.0 (compare)

  • Sep 14 15:50

    depfu[bot] on update

    (compare)

  • Sep 14 15:50
    depfu[bot] closed #189
  • Sep 14 15:50
    depfu[bot] commented #189
Árni Gunnarsson
@arni1981_gitlab
@sebastjan-hribar Great, I had exactly the same misunderstanding about how this works just a few days ago.
Sebastjan Hribar
@sebastjan-hribar
@arni1981_gitlab I hadn't thought to look at dry.rb docs :(
Phillip Oertel
@phillipoertel
Hi everyone, I'm trying to figure out how to get the application & and controller which handles a request. I'm using Hanami 1.3.3.
Phillip Oertel
@phillipoertel

Some pseudocode:

def figure_out_handler(rack_env)
  # some calls to Hanami routing in here ...
  "#{application_name}/#{controller_name}#{action_name}"
end

I have several apps (Web and Api, more TBD), mounted at / and /api. If I had just one app, I could call MyApp.routes.recognize(env).action on it, but I with my setup I think I have to go through Hanami.app to resolve things, which I haven't been able to figure out.

I'd like to use this to add an Hanami-instrumentation for the appsignal service and gem.

adam12
@adam12_:matrix.org
[m]
@phillipoertel: You'll probably have to go into the internals. Right before the route is dispatched, presumably it's creating an instance to call. Maybe you could manipulate the Rack env there.
Phillip Oertel
@phillipoertel
@adam12_:matrix.org thanks for your reply. I dug through the internals a little more and came up with a working but ugly and possibly brittle solution:
class PathResolver
  def self.call(path)
    new.call(path)
  end

  def call(path)
    app_configs = Hanami.configuration.mounted.values
    app_configs.map do |app_config|
      return 'root' if path == '/'
      next unless path.start_with?(app_config.path_prefix)

      # returns Api, Web, ...
      app_constant = Module.const_get(app_config.to_s.split('::').first)

      relative_path = path.split(app_config.path_prefix).last

      # returns either nil or something of the form "web_controllers/alive#index"
      app_constant.routes.recognize(relative_path).action
    end.compact.first # return first non-nil value
  end
end
Welcoming any help to make this simpler and more robust ...
Phillip Oertel
@phillipoertel
The above also fails for a route with HTTP PATCH...
Sebastjan Hribar
@sebastjan-hribar
@phillipoertel This is just to let you know I came up with a similar - what looks an ugly - solution to find a particular controller and action in a request. I have a before block that takes an action and finds both like this:
controller = self.class.to_s.split("::")[2]
action = self.class.to_s.split("::")[3]
Árni Gunnarsson
@arni1981_gitlab
What would be the best way to play around with Hanami2, I didn't see anything on the github page or the main hanami page.
adam12
@adam12_:matrix.org
[m]
@arni1981_gitlab: I'd start with Tim's application template, since it's what will be very similar to the what the Hanami 2 CLI will generate. https://github.com/timriley/hanami-2-application-template
Phillip Oertel
@phillipoertel
I asked about a mapping from request path to Hanami app/controller/action recently. Here's what I came up with, maybe it helps someone: https://gist.github.com/phillipoertel/5d99e66d6181b037697cbfce9d0a6d5f
Marcus Pereira
@marcuxyz
thanks
hi, guys! i'm a new user of hanami. I'm creating tests with capybara, How can i to clear database for each test runned?
adam12
@adam12_:matrix.org
[m]
@marcuxyz: I'd look at database_cleaner gem.
Sebastjan Hribar
@sebastjan-hribar
@marcuxyz You could also call the clearmethod on a repo in a before or after block.
Marcus Pereira
@marcuxyz
thanks @adam12_:matrix.org and @sebastjan-hribar for help me
Mark Plaksin
@happymcplaksin_twitter
How do I add an association by ID? Apologies if this is obvious, I can't figure it out :) As an example, let's say I have a book object already and want to add it to an author? IIUC, the example add_book will create the book and doesn't work when passed an ID (or a book object) https://guides.hanamirb.org/associations/has-many/#add-and-remove
Thomas Carr
@TommyHanami
Hi I'm working my way through the guides, and am running into an issue on the interactors section. I think there's a missing instruction on updating the routes file for the create action, but even when I add a posts book => books#create to the file my tests still fail with Hanami::Routing::InvalidRouteException:
No route (path) could be generated for :books - please check given arguments
Edouard
@inouire_twitter
Can you be more specific on the syntax you use, and in which file ?
Árni Gunnarsson
@arni1981_gitlab
I'm trying out hanami-controller from the unstable branch, and this gives me the dreaded uninitialized constant Hanami::Controller::Configuration
Hanami::Controller::Configuration.new do |config|
Thomas Carr
@TommyHanami
@inouire_twitter I may have made a mistake in the previous section on the books#new form, let me correct this and see if this solves my issue.
Sebastjan Hribar
@sebastjan-hribar
Hi, I'm setting a session variable in app A and it's not available in the default Web app once redirect happens. It's available in the source app though. Is this expected behavior?
Sebastjan Hribar
@sebastjan-hribar

Hi, I'm setting a session variable in app A and it's not available in the default Web app once redirect happens. It's available in the source app though. Is this expected behavior?

I've inspected session IDs in the origin app and in the target redirected app and they are different. So how can/should I pass the session variables from one app to the next? I need this for authentication and currently it doesn't work due to this behavior.

Edouard
@inouire_twitter
Did you try sharing the same secret string for the cookie ?
Sebastjan Hribar
@sebastjan-hribar
@inouire_twitter No, and I honestly did not now this :(
I've just tried it and it works.
@inouire_twitter Thank you!
I always hate these moments of feeling stupid :)
Edouard
@inouire_twitter
@sebastjan-hribar no worry, I discovered it by chance. Not sure that it's really a feature though ^^
Sebastjan Hribar
@sebastjan-hribar
@inouire_twitter I have another problem with sessions. We have a lot of ajax calls and when sessions are enabled these calls cause the invalid csrf token error. For now I've disabled this by overwriting the verify_csrf_token?, but this seems not the way to go in production. What is the way to go about this?
Sebastjan Hribar
@sebastjan-hribar
For what is worth, we tried providing the token via the ajax call, but no success yet.
Edouard
@inouire_twitter
@sebastjan-hribar it seems that you do not generate forms with the official helper, so your forms do not include CRSF token, which is checked
The token doesn't make sense if you don't have any session, so that could be why it's working when you disable sessions
You could use form_for helper, or recreate CRSF token by yourself, or disable crsf token verification as you already do.
Sebastjan Hribar
@sebastjan-hribar

@inouire_twitter True, in these cases there are no forms generated with the official helper and sessions are enabled for the app in question. We use 1 template to build a complex editor supporting multiple ajax calls to different interactors.
Here is one code example:

$.ajax({
    type: "POST",
    url: "/wordrocket/term_records",
    datatype: "json",
    data: {term_record:
          {
      source_term: $("#tmsr-wr-input-source-term").val(),
      target_term: $("#tmsr-wr-input-target-term").val(),
      src_language: $("#tmsr-wr-select-source-language").val(),
      trg_language: $("#tmsr-wr-select-target-language").val(),
      domain_id: $("#tmsr-wr-select-term-domain").val(),
      definition: $("#tmsr-wr-textarea-term-definition").val()
          }
    },

So, is disabling csrf token verification safe in such cases?
How would we recreate and pass the token? I've been searching online for hanami (a few mentions in gitter from the Lotus times) and non-hanami references, but I still don't know how to do this.

Edouard
@inouire_twitter
About disabling the crsf check, it depends on your use case... is it sensible if a form is forged by an malicious software ? https://owasp.org/www-community/attacks/csrf
About recreating it, I'd guess that the logic is somewhere in https://github.com/hanami/helpers but I didn't find it yet
Sebastjan Hribar
@sebastjan-hribar

About recreating it, I'd guess that the logic is somewhere in https://github.com/hanami/helpers but I didn't find it yet

Yes, I've been looking there as well, but even if were to use the form helper, I don't suppose we'd have access to the token itself.

Sebastjan Hribar
@sebastjan-hribar
This seems to be the way to go, I guess.
Sebastjan Hribar
@sebastjan-hribar
By simply adding <%= csrf_meta_tags %> in the app html head the invalid csrf token error still occurs, eventhough the csrf tag and content are generated.
Sebastjan Hribar
@sebastjan-hribar
In addition to adding the above code to the app head, we have to pass it in the data:
var token = $('meta[name="csrf-token"]').attr('content')
    $.ajax({
    type: "POST",
    url: "/wordrocket/term_records",
    datatype: "json",
    data: {
    _csrf_token: token,
And it works :)
Edouard
@inouire_twitter
cool !
interesting feedback, thanks
Sebastjan Hribar
@sebastjan-hribar
And now that I've worked it out, it makes perfect sense, as usual. :)
Sebastjan Hribar
@sebastjan-hribar
I've made docs PRs for sessions and the above CSRF with UJS for future reference.
Edouard
@inouire_twitter
:thumbsup:
Kori Roys
@koriroys
Hey y'all. How would I go about setting a param programmatically if it's not set (before validating or coercing params)
Edouard
@inouire_twitter
based on what input would the params be set ?