Forum https://discourse.hanamirb.org – Code of Conduct http://hanamirb.org/community/#code-of-conduct
mereghost on update-dry-types
Update code for dry-types 1.2.2 (compare)
mereghost on update-dry-types
Update code for dry-types 1.2.2 (compare)
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
Hi, I’m trying to do some basic timezone stuff but my google-fu is failing me.
What I want to achieve:
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
hanami-utils
v1.3.4 and hanami-view
v1.3.2 https://twitter.com/hanamirb/status/1177498984551612416
Well first of all, there is not ActiveSupport::TimeWithZone
equivalent in Hanami. So if you need complex time zone stuff - and basic Ruby is really lacking there - you'll need to pull in a Gem for that.tzinfo
has recently improved the interfaces/usability of it's classes, but I haven't checked that out yet. A couple years ago when I was working a lot with time zones I wrote my own gem because ActiveSupport::TimeWithZone
had some nasty bugs and while I liked the interface had many design decisions I did not like, plus it was difficult to get JUST time with zone and not all the rest.
I still regularly update that gem whenever there's a new tzinfo release, but I consider it "done". It focuses on correctness and ease of use over speed though.
But there is a gazillion other gems out there, any of which may do what you need. And if you don't have complex timezone needs, I'd suggest to stick with plain ruby as long as comfortably possible.
hanami db prepare
postgresql://postgres:SuperStrongPassword@localhost/hanami_app_development
postgres
is the user name
What is the recommended way to prevent accidently exposing a XSS vulnerabilities in a view template? The hanami doc’s reccomend either explicitly providing methods for the template in the view e.g.
def user_name
user.name
end
Or escaping the whole object before sending it to the template
def user
_escape locals[:user]
end
Although this does not prevent accidentaly calling user.name
in the view, or in the case of the _escape
escaping the assoications of the object e.g. user.notes
Haml::Template.options[:escape_html] = true
light-service
gem (https://github.com/adomokos/light-service) with Hanami?
activesupport
(since it's looking for it when I run tests) and now I'm getting that error which I'm not familiar with