Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 11:20

    timriley on application-settings

    Update integration spec to cove… (compare)

  • 11:12

    timriley on application-settings

    Move Undefined into a place tha… Address Rubocop issues (compare)

  • Dec 13 19:56
    mfurkandemir starred hanami/hanami
  • Dec 13 18:56
    IvanShamatov closed #1022
  • Dec 13 18:56
    IvanShamatov commented #1022
  • Dec 13 11:53
    muriloime starred hanami/hanami
  • Dec 13 10:15
    depfu[bot] labeled #190
  • Dec 13 10:15
    depfu[bot] opened #190
  • Dec 13 10:15

    depfu[bot] on update

    Update dry-validation to versio… (compare)

  • Dec 12 23:39
    IvanShamatov review_requested #1021
  • Dec 12 23:38
    IvanShamatov edited #1021
  • Dec 12 23:37
    IvanShamatov edited #1021
  • Dec 12 21:49
    IvanShamatov synchronize #1021
  • Dec 12 20:45
    IvanShamatov synchronize #1021
  • Dec 12 13:07
    enkos starred hanami/hanami
  • Dec 12 12:19
    maxloh starred hanami/hanami
  • Dec 12 12:12
    IvanShamatov synchronize #1021
  • Dec 12 11:40
    helmihidzir starred hanami/hanami
  • Dec 12 09:18
    IvanShamatov synchronize #1021
  • Dec 12 04:55
    ryanbreed starred hanami/hanami
hfabre
@hfabre
@kaikuchn haha no problem, so after a week-end of rest do you have any idea ? :smile:
Kai Kuchenbecker
@kaikuchn
I'm thinking that, since you're doing everything as is done in the hanami/model test suite - which is green, there must be some difference in setup that foils this.
So, what database are you using and can you show us the schema of your table? As the database tool of your choice reports it.
hfabre
@hfabre

Since it's for work I don't think I can show all the db schema, but I'll try show an anonymized version of the table .

I don't really know why but the tooling is really split in this project, we rely on MySQL 5.6, Hanami 1.x (Entity/Repositories), Rails router and migrations

hfabre
@hfabre
btw I saw in ROM you can do schema(infer: true) { # ... } and only define specific attributes. It would be awesome to have the same feature in Hanami so we don't have to detail all the table schema for only one column
hfabre
@hfabre
Oh, finally found it !
hfabre
@hfabre
thanks for your time @kaikuchn really appreciate that :)
Kai Kuchenbecker
@kaikuchn
Glad I could be a helpful rubber duck :D
It's interesting that you need to specify the primary key while they don't do it in the hanami test suite. Probably has something to do with the type of database and/or how the table is defined.
I suspect that the next version of hanami will sport a much better integration with the ROM/Dry universe since we closely collaborate with them.
hfabre
@hfabre
Yes, I can't really understand why it didn't works as this.

I suspect that the next version of hanami will sport a much better integration with the ROM/Dry universe since we closely collaborate with them.

Good to know !

Tsehau Chao
@jodeci

Hiya, I’m trying out hanami (for fun) with the guides.

Take the download_count example:
https://guides.hanamirb.org/helpers/numbers/

If this was within the Web::Views::Books::Index context, what’s the hanami way to implement something like:

<% books.each do |book| %>
  <p>book.download_count</p>
<% end %>

Which obviously doesn’t work, but download_count(book) also feels wrong?

Kai Kuchenbecker
@kaikuchn
I assume you are wondering how to perform view related transformations on an each entity in a collection view? I'd implement a decorator and wrap the entities - if it's strictly view related. If that seems like too much work for you or feels like over-engineering - which it may very well be for very simple cases - you can also go with download_count(book).
Tsehau Chao
@jodeci
Your assumption is correct! Let’s say that a decorator is needed. Is there a well used gem in the ecosystem (e.g. draper for rails) or do we just cook our own food?
Kai Kuchenbecker
@kaikuchn
http://awesome-hanami.org/ does not list a decorator-gem (it's a curated list of gems that are known to work with hanami). I personally have just used on of Ruby's builtin facilities (SimpleDelegator, Forwardable , DelegateClass, extending instances with a module, etc.). I therefore don't know if such a gem exists.
I'm also not sure what value such a gem would provide.
Kai Kuchenbecker
@kaikuchn
class BookDecorator < SimpleDelegator
  include Web::View

  def download_count
    format_number __getobj__.download_count
  end
end

books.map { |book| BookDecorator.new(book) }
Seems simple enough to me. No need for a gem.
Tsehau Chao
@jodeci
Cool, gonna mess around with it a bit, thanks :D
David Dawson
@DangerDawson
Is there any benefit in using the Rack::Protection gem? or am I right in thinking that Hanami already gives us the same protection?
alex jamz
@alexjamz_gitlab
I using MODERATION_SESSIONS_SECRET and WEB_SESSIONS_SECRET env variables before start Hanami, so Rack::Protection::SessionHijacking not needed. Bigger part of your gem Rack::Protection is not needed, see application.rb security.* settings.
unleashy
@unleashy

hi, i created a brand new hanami 1.3.3 app with hanami new, everything default. then i generated a home#index action using hanami generate action web home#index, and when i access that page I get this error https://i.imgur.com/44ilnqF.png (NameError at uninitialized constant Hanami::View::Rendering::Scope::String)

i've searched in google and github but i can't find anything about this error. does anyone know how to fix it? if this is not the right place to ask please direct me to the correct place, thank you!

Edouard
@inouire_twitter
Hi @unleashy , I just tried to upgrade my version of Hanami from 1.3.2 to 1.3.3 and this is what is causing the error. 1.3.2 works fine
unleashy
@unleashy
ah, thank you! seems there was a regression then?
Edouard
@inouire_twitter
Seems like it, yeah.
Edouard
@inouire_twitter
@jodosha issue created :point_right: hanami/hanami#1015
unleashy
@unleashy
okay, regressing to hanami 1.3.2 didn't work for me, but! regressing the tilt gem to 2.0.9 worked
Edouard
@inouire_twitter
OOOh
unleashy
@unleashy
I think 2.0.10 inadvertently broke something with hanami
Edouard
@inouire_twitter
good to know :thumbsup:
unleashy
@unleashy
rtomayko/tilt@dbb4df9 this commit, I believe
alex jamz
@alexjamz_gitlab
tilt 2.0.10? Same here...
unleashy
@unleashy
yeah it's def on tilt's side. rtomayko/tilt#347
too bad
Stephann Vasconcelos
@stephannv

Hello guys. How hanami handles routes with subdomains? I'm working on a project with a subdomain per client and I didn't figure out how to handle this using Hanami. In Rails I found some references:

# application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :ensure_subdomain

  def current_blog
    @current_blog ||= Blog.find_by(subdomain: request.subdomain)
  end
  helper_method :current_blog

  private

  def ensure_subdomain
    redirect_to root_url(subdomain: :www) unless current_blog.present?
  end
end

# routes.rb
Rails.application.routes.draw do
  constraints(SubdomainRoutes) do
    resources :blogs, only: [:new]
    root 'welcome#index'
  end

  constraints(!SubdomainRoutes) do
    resources :blogs, except: [:index, :new] do
      resources :posts
    end
    root 'blogs#show'
  end
end

# subdomain_routes.rb
class SubdomainRoutes
  def self.matches? request
    case request.subdomain
    when '', 'www'
      true
    else
      false
    end
  end
end

Source: https://www.driftingruby.com/episodes/working-with-subdomains

Kai Kuchenbecker
@kaikuchn
@stephannv I'd suggest to have your reverse proxy rewrite the subdomain to a distinct path, that way your app can be agnostic of the domain.
It is possible to mount different apps on different hosts in Hanami, but I don't know if you can route to different targets in the same app depending on the host.
Kai Kuchenbecker
@kaikuchn
Under the hood hanami uses the http_router gem, i think it's possible to just add host: "www.blabla.org" to your route, if it's not the http_router gem also allows for customizations via extend_route. So you could probably also go that way..
Stephann Vasconcelos
@stephannv
Thanks, @kaikuchn
I will research more about this topic
unleashy
@unleashy
hi y'all, i have a question. is it good practice to use defined? to check if an exposure is available or not? or should i use something else?
Kai Kuchenbecker
@kaikuchn
Best if to have the exposure always available. Maybe use the NullObject pattern. Let me rephrase that: Have you considered making your exposures always available? Maybe use the NullObject pattern.
I personally try to never have more than one exposure, similarly how I would avoid using more than one instance variable in a rails controller.
David Dawson
@DangerDawson
I have another security question, has anyone used Rack::Attack with multiple apps? I am struggling to get this working with trying to define app specific rules, they seem to get applied globally
David Dawson
@DangerDawson
Also am I right in thinking that the template does no escaping? it is all handled at the view layer? e.g. <%= user.last_name %> will not be escaped?
David Dawson
@DangerDawson
Answers my question quite nicely
unleashy
@unleashy
@kaikuchn thank you, that makes total sense!
Tsehau Chao
@jodeci

Hi, I’m trying to do some basic timezone stuff but my google-fu is failing me.
What I want to achieve:

  1. set default timezone for application (say UTC+8)
  2. user input: 2019-01-01 20:00
  3. entity saved as 2019-01-01 12:00:00 UTC
  4. template displays time as 2019-01-01 20:00:00 UTC+8

3 & 4 works right out of the box, but I’m lost at 1 & 2. The closest thing I found was:

# config/initializers/sequel.rb
Sequel.application_timezone = :local

But everything is still saved as 2019-01-01 20:00:00 UTC. Timezones are hard :p

Kai Kuchenbecker
@kaikuchn
I don't think it's a good idea to have sequel handle that. It's like the very furthest point from your users input.
I'd instead suggest to handle the user input that comes without a timezone as if it would specify your default timezone.