Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 11 21:49
    maxloh starred hanami/hanami
  • Dec 11 20:41
    IvanShamatov synchronize #1021
  • Dec 11 20:08
    wout forked
    wout/model
  • Dec 11 20:04
    wout forked
    wout/hanami
  • Dec 11 14:35
    jodosha assigned #1021
  • Dec 11 08:50
    IvanShamatov synchronize #1021
  • Dec 11 05:34

    timriley on application-settings

    Make container aware of lib loa… (compare)

  • Dec 11 05:24

    timriley on application-settings

    Allow settings to be nil It sh… Fix Syntax (compare)

  • Dec 11 05:09

    timriley on application-settings

    Add rough cut of settings suppo… Be more proactive loading doten… Remove unnecessary eval and 19 more (compare)

  • Dec 10 13:51
    TatsukiMinami starred hanami/hanami
  • Dec 10 13:43
    IvanShamatov synchronize #1021
  • Dec 09 21:27
    IvanShamatov synchronize #1021
  • Dec 09 21:27
    IvanShamatov edited #1021
  • Dec 09 21:21
    IvanShamatov opened #1022
  • Dec 09 20:59
    IvanShamatov opened #1021
  • Dec 09 20:49
  • Dec 09 12:20
    s4na starred hanami/hanami
  • Dec 09 10:28

    mereghost on update-dry-types

    Update code for dry-types 1.2.2 (compare)

  • Dec 09 10:14

    mereghost on update-dry-types

    Update code for dry-types 1.2.2 (compare)

  • Dec 08 12:06
    sebastjan-hribar opened #1020
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.
If there are many places where user input can happen, then extract that handling into a little PORO that does the magic for you.
There's probably nothing that does out of the box what you want, but I may be mistaken. If so, others please feel free to chime in.
Tsehau Chao
@jodeci
Hmm. Interesting that app wide time zone configuration doesn’t come with the box. I might be biased though (worked on a Rails app with heavy timezone focus recently)
Luca Guidi
@jodosha
:mega: Released hanami-utils v1.3.4 and hanami-view v1.3.2 https://twitter.com/hanamirb/status/1177498984551612416
Edouard
@inouire_twitter
:thumbsup: