by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 12:16
    maikelcoke starred hanami/hanami
  • 10:32

    timriley on unstable

    (compare)

  • 10:32

    timriley on unstable

    Reintroduce CSRFProtection modu… (compare)

  • 10:32
    timriley closed #327
  • Sep 22 22:13
    clsource starred hanami/hanami
  • Sep 22 10:41

    jodosha on unstable-rubocop-hanami-dry-rb-rules

    (compare)

  • Sep 22 10:41

    jodosha on unstable

    Rubocop Hanami dry-rb rules (2.… (compare)

  • Sep 22 10:41
    jodosha closed #117
  • Sep 22 10:33
    jodosha milestoned #117
  • Sep 22 10:33
    jodosha labeled #117
  • Sep 22 10:33
    jodosha assigned #117
  • Sep 22 10:33
    jodosha opened #117
  • Sep 22 10:32

    jodosha on unstable-rubocop-hanami-dry-rb-rules

    MRI 2.6+ and Rubocop 0.91 `Style/StringConcatenation` `Style/RedundantRegexpEscape` and 6 more (compare)

  • Sep 22 09:47

    jodosha on unstable

    Run integration specs in CI (#1… Drone CI (#105) Use SassC in place of Sass (EOL… and 12 more (compare)

  • Sep 22 08:15

    jodosha on develop

    Use binary mode when writing fi… Prepare for v1.3.4 Official support for Ruby 2.7 (… and 2 more (compare)

  • Sep 21 15:40
    AdamDubnytskyy starred hanami/controller
  • Sep 21 15:40
    AdamDubnytskyy starred hanami/view
  • Sep 21 14:45

    jodosha on master-rubocop-hanami-dry-rb-rules

    (compare)

  • Sep 21 14:42

    jodosha on master

    Rubocop Hanami dry-rb rules (1.… (compare)

  • Sep 21 14:42
    jodosha closed #116
kristjan-brezovnik
@kristjan-brezovnik

I got LESS to work with Hanami!:D
I was going to post the whole troubleshooting process, but it would be too long, so I'll just reiterate what worked for me. This presupposes that your stylesheet file is called styles.css.less. The .less suffix is mandatory.

Some links first:
LESS precompiler site: http://lesscss.org/
Direct link to JS file: https://cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js
W3.CSS download page: https://www.w3schools.com/w3css/w3css_downloads.asp
Direct link to main W3.CSS stylesheet: https://www.w3schools.com/w3css/4/w3.css

The setup:
Install therubyracer and less gems:

gem install therubyracer
gem install less

Put the following lines in the Gemfile file:

gem 'therubyracer'
gem 'less'

In the application.html.erb file of your app, put the following lines:
<%= stylesheet 'styles' %> (without .css.less suffixes!!!) after the other stylesheets
and
<%= javascript 'less.min' %> (with or without the .js suffix) just before the end of the body.
Note that if you use a CDN, you will likely have to modify the Content Security Policy to allow access.

Put the styles.css.less file (with the .css.less suffixes) in your apps/<YourApp>/assets/stylesheets folder and the less.min.js (with the .js suffix) in your apps/<YourApp>/assets/javascripts folder (if you're using it locally).

That's it!

The use:
If you use other stylesheets and want to use their classes in mixins, you first need to import them. In the styles.css.less file, add the following line at the beginning (the example is for the W3.CSS stylesheet):

@import (less) "w3.css";

Then you can do the following, for example:

.tmsr-card-list-item-link-index{
    .w3-padding();
}
select {
    .w3-select()
}
.tmsr-form-row{
  .w3-section();
}
.tmsr-form-row:extend(.w3-row-padding all){}
.tmsr-form-field2:extend(.w3-row-padding, .w3-col, .w3-half all){}

Note, the ":extend" pseudo-class and the "all" keyword with the last two entries. The ":extend" pseudo-class basically extends your class with the W3.CSS class. The "all" keywords means that it will find all instances. In principle, I think you could do all entries with ":extend", but I haven't tested it. The reason for both types of entries is because some classes break LESS. Which ones you'll have to figure out for yourself.

Anyway, it would be nice if someone could independently MTC this, to make sure nothing else on my setup affected this. I tried this twice and it worked.

Other thant that, happy preprocessing!:D

smarthouseprojectdotorg
@smarthouseprojectdotorg

When implementing a destroy action in my controller's code using redirect_to keeps the original i.e. DELETE HTTP method for redirection. Is it an expected behaviour?

ClientRepository.new.delete(params[:id])
redirect_to routes.clients_index_path

HTTP/1.1 DELETE 302 127.0.0.2 /admin/clients/4 5 {"id"=>"4"} 0.019853
HTTP/1.1 DELETE 405 127.0.0.2 /admin/clients - {} 0.007363

I ended up with using halt 200 in the controller's code instead of redirect_to and doing a redirection from JS

Kai Kuchenbecker
@kaikuchn
No, that's not right.
Something is wrong there. It works perfectly for my app:
[notification] [INFO] [2019-11-28 10:03:20 +0100] HTTP/1.1 DELETE 302 ::1 /notifications/alerts/373 5 {"_method"=>"DELETE", "_csrf_token"=>"f352a44fe416edbf1f2c4bf1f13773c99f6edf9c30012d15bac14db7003c10be", "id"=>"373"} 0.045338
[notification] [INFO] [2019-11-28 10:03:20 +0100] (0.000604s) SELECT "id", "topic", "criterion", "action", "created_at", "updated_at", "name" FROM "alert_rules" ORDER BY "alert_rules"."id"
[notification] [INFO] [2019-11-28 10:03:20 +0100] HTTP/1.1 GET 200 ::1 /notifications/alerts 4629 {} 0.032162
I wonder about your route name @smarthouseprojectdotorg clients_index_path sounds wrong to me. Shouldn't it be clients_path?
Maybe show us your route definitions. Also, what version of Hanami are you using?
Eric
@ericplezi

Hi guys,

I'm requesting your help!
I'm using Hanami controller coupling with Rails. For some reason I can't figure why my application is not outputting logs info in staging environment. ActiveSupport does not seem to work out with Hanami controller use only. We made sure the testing config file is enabling logs output.
Any idea what I could be doing wrong?

Your feedbacks are appreciated, thanks!

Kai Kuchenbecker
@kaikuchn
Hanami, and Rails for that matter, actually use the standard logging interface. So you should be able to plug the ActiveSupport logger into hanami-controller without problems (mind you, I have never tried this!). Maybe the configured log-level is not what you expected?
Eric
@ericplezi

this is what I have in the config.ru file:

console = ActiveSupport::Logger.new($stdout)
console.formatter = Rails.logger.formatter
console.level = Rails.logger.level

Rails.logger.extend(ActiveSupport::Logger.broadcast(console))

run Rails.application

the log-level is set to :debug
somehow it doesn't print the http request info (duration, params, ip address, etc). is there a middleware to add?

Kai Kuchenbecker
@kaikuchn
Right, so I just had a look into hanami/controller and it seems that it's not responsible for logging requests. I'm guessing some rack middleware does that. I'll have to further look into it.
Yeah, the hanami/hanami gem wires logging up.
It uses a common_logger component that is based on the rack/common_logger.
Kai Kuchenbecker
@kaikuchn
I.e., I suppose you could insert rack/common_logger into your middle-ware stack and you should get your request logs.
Kai Kuchenbecker
@kaikuchn
You may also consider using this: https://api.rubyonrails.org/classes/Rails/Rack/Logger.html
Which is the rails middleware for request logging.
Without knowing how you integrated hanami/controller into your rails app I'm not sure what makes sense and what doesn't :)
Eric
@ericplezi
I added rack/common_logger file in my project and added require 'rack/common_logger' in my config.ru
nothing was printed :(
Michael Trommer
@entropie
How does one access cookies from the view? Works fine from the controller, I feel I must miss something.
Kai Kuchenbecker
@kaikuchn
@ericplezi You need to insert the middleware it as well!
@entropie why would you? wouldn't it be better to expose a variable to the view?
Eric
@ericplezi
I added the middleware @kaikuchn
Kai Kuchenbecker
@kaikuchn
Ah ok. Where did you add it?
Eric
@ericplezi
in the lib folder under rack/common_logger.rb
Kai Kuchenbecker
@kaikuchn
No, I mean where in the middleware-stack did you insert it? See this guide to middleware if you're unsure on what to do.
Eric
@ericplezi
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'
require 'rack/common_logger'


console = ActiveSupport::Logger.new($stdout)
console.formatter = Rails.logger.formatter
console.level = Rails.logger.level

#Hanami::Logger.extend(ActiveSupport::Logger.broadcast(console))
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))

run Rails.application
here I added it
Kai Kuchenbecker
@kaikuchn
There you simply required it. But now you also need to insert it into the middleware-stack. See the guide I posted in my previous message on middlewares / rack.
Eric
@ericplezi
yeah i'm not sure where to added it and how to include it
Eric
@ericplezi
I added config.middleware.insert_before 0, Rack::CommonLogger in the application.rb
seems to do the job
Thanks mate @kaikuchn !
Kai Kuchenbecker
@kaikuchn
:+1:
Michael Trommer
@entropie
@kaikuchn yeah probably, but I dont know how to access #cookies from the view context as well
Michael Trommer
@entropie
ok, i did a before :hook and set a variable.
Kai Kuchenbecker
@kaikuchn

but I dont know how to access #cookies from the view context as well

Well pass it from the Action via Exposure to the View, as you'd do with anything else.
If you need it to be present for every View, you can also make use of the prepare hooks in the application.rb file.

Kai Kuchenbecker
@kaikuchn
E.g.,
module Web::BakedViews
  def self.included(action)
    action.class_eval do
      exposure :cookie
      before :bake_ma_view
    end
  end

  def bake_ma_view
    @cookie = cookies[:grannys_tasty_cookies]
  end
end

# web/application.rb
# ...
  controller.prepare do
    include Web::BakedViews
  end
Hmm, actually, before might be nicer since it doesn't overwrite the call action, yeah I'll edit the above accordingly.
smarthouseprojectdotorg
@smarthouseprojectdotorg

Thanks @kaikuchn I'm using named routes. This is it

get '/clients', to: 'clients#index', as: :clients_index

Can you think of anything else to check? It's more a theoretical question though as I think it should redirect using GET but I won't use it as redirection from 'destroy' action make sense only if a form is used for calling the deletion. Using a form for this seems weird and I ended up with AJAX hence don't need to redirect now. But that raised a question about a proper way of sending DELETE in Hanami. <form>, AJAX do we we have anything else which would look as nice as link_to for 'edit' and 'new' ?

kristjan-brezovnik
@kristjan-brezovnik
Is it possible to have a JS or JSON file under assets and expose an array, then loop through that array in a template? Basically, I have a list of items, which all get the same HTML container around them, so I don't want to needlessly duplicate the code.
kristjan-brezovnik
@kristjan-brezovnik
Ah, figured it out:
<% tiles = %w[item1 item2] %>
<% tiles.each do |tile| %>
<h1><%= tile %></h1>
<% end %>
Sebastjan Hribar
@sebastjan-hribar
What would be the reason for a flash not to render? I have sessions enabled for the app and set flash as flash[:error_m] = params.error_messages. puts flash[:error_m] works and I see all messages in the server output. The template has simply this code <%= flash[:error_m] %> and nothing renders.
Sebastjan Hribar
@sebastjan-hribar
It's like the flash is not exposed, although they should be by default. I've put an if statement to the template to check for flash[:error_m] and only the false branch executes.
Sebastjan Hribar
@sebastjan-hribar
So, it works for another entity. After some comparing, I saw in the server output these two lines (overlooked them before due to long list of errors and small console):
Warning! Rack::Session::Cookie data size exceeds 4K.
Warning! Rack::Session::Cookie failed to save session. Content dropped.
Kai Kuchenbecker
@kaikuchn
@smarthouseprojectdotorg well Hanami is giving you a 302 response, the question is why the browser then sends a delete request again. So I'm guessing it's something in your client-side javascript that's behaving in a weird way?
smarthouseprojectdotorg
@smarthouseprojectdotorg

@kaikuchn no, just tested, seems it's definitely Hanami which is trying to do a redirect keeping the original HTTP method, i.e. DELETE in case of my destroy action.
This is the action code below, see I disabled halt and enabled redirect_to. Did not change anything else since I moved to AJAX for this, but the below is still OK for this test as only checking the log. clients_index_path route does work - tested separately with link_to

        def call(params)
          ClientRepository.new.delete(params[:id])
          #halt 200
          redirect_to routes.clients_index_path
        end

Result:

HTTP/1.1 DELETE 302 127.0.0.2 /admin/clients/8 5 {"id"=>"8"} 0.015793
HTTP/1.1 DELETE 405 127.0.0.2 /admin/clients - {} 0.007453
HTTP/1.1 GET 200 127.0.0.2 /admin/clients 1856 {} 0.016227

The last line is my test of the route with GET. So definitely in case of HTTP DELETE, route_to tries to do a redirect using the same DELETE method. Obviously it is not supported by my routes and hence 405. Question - is it a bug or a feature? Anyway seems reasonable if redirect_to could always use GET or had an option to specify the method.

Kai Kuchenbecker
@kaikuchn

This is how to read those logs:

  • Received DELETE Request using HTTP/1.1 from 127.0.0.2 for path /admin/clients/8, responded with 302 within 0.015793 seconds
  • Received DELETE Request using HTTP/1.1 from 127.0.0.2 for path /admin/clients, responded with 405 within 0.007453 seconds

So you are sending two delete requests, why ever you are doing this. I'm pretty sure that it's not something Hanami is doing, like 99%. The third request you send is then the get request I'd expect after Hanami had send your client a redirect response. The 2nd request is weird.

Kai Kuchenbecker
@kaikuchn
The 1% is because maybe there is some client-side javascript that hanami generated for you that does that weird request.. but that's the only explanation I can come up with where the second delete request does not come from your client-side code.
Captain Husayn Pinguin
@captainhusaynpinguin
Hi there, a stupid newbie question. How do you do dump like rails or var_dump like PHP in Hanami in the middle of somewhere?
self.body = XYZ only works in controller modules!