by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 13 14:04
    unhappychoice commented #202
  • Jul 13 13:52
    jodosha commented #202
  • Jul 13 13:52
    unhappychoice commented #202
  • Jul 13 13:52
    unhappychoice closed #202
  • Jul 13 13:51
    unhappychoice commented #202
  • Jul 13 13:41
    jodosha labeled #202
  • Jul 13 13:41
    jodosha assigned #202
  • Jul 13 13:41
    jodosha commented #202
  • Jul 13 12:58
    unhappychoice edited #202
  • Jul 13 12:54
    unhappychoice edited #202
  • Jul 13 12:54
    unhappychoice edited #202
  • Jul 13 12:53
    unhappychoice edited #202
  • Jul 13 12:52
    unhappychoice edited #202
  • Jul 13 12:52
    unhappychoice edited #202
  • Jul 13 12:52
    unhappychoice edited #202
  • Jul 13 12:51
    unhappychoice edited #202
  • Jul 13 12:51
    unhappychoice edited #202
  • Jul 13 12:44
    unhappychoice opened #202
  • Jul 13 10:08
    timriley edited #1067
  • Jul 13 00:52
    timriley pinned #1067
Ivan Rubanovskiy
@xvonabur
Hi! Does Hanami supports composite keys in hanami-model? I saw old issue on GitHub, but it's 2 years old: hanami/model#432
Kai Kuchenbecker
@kaikuchn
Folks, I just learned that Ruby 2.7 preview has Enumerator.produce and I'm loving it. Why isn't there more noise about this absolutely fantastic (experimental) addition to Ruby? Check it out
With this I'll never have to write a while loop again x)
Matt
@matt-from-toronto
i just took a look through the guide, hanami looks frickin awesome. congrats all! really love how repositories and entities are separated (i hate models in rails), and love the interactors concept too, callbacks have been very painful for me to work with
i'd love to know what are the some impressive apps built using hanami that are currently being used in production. i've taken a look through http://awesome-hanami.org/#awesome-hanami-hanami-project-list and am wondering if there's more to add to that list
calebbarde
@calebbarde
Hi all - a silly question likely - but coming from Rails and AR, I'm used to validation at both a request level and a model level. Is it idiomatic in hanami to have entity validations (in additions to the automatic schema validations)?
Is there an "idiomatic" hanami project on http://awesome-hanami.org/#awesome-hanami-hanami-project-list (stolen from @matt-from-toronto :) ) that would be a good one to reference overall?
Matt
@matt-from-toronto
@calebbarde you can add custom scheme validations to an entity it seems. https://guides.hanamirb.org/entities/custom-schema/ what validation do you want to add that can't be covered by schema validations, whether automatic or custom?
actually I think I've misunderstood your question
I'd also love to know if there's an idiomatic hanami project, I haven't stumbled across one yet FWIW
calebbarde
@calebbarde

Ah yes I saw that - I was interested as to that - a note there

Custom schema takes precedence over automatic schema. If we use custom schema, we need to manually add all the new columns from the corresponding SQL database table.

Which is unclear to me. If I use custom schema attributes, does it completely override the other columns? Or can I use both - sometimes its just nice to have some overlying business logic validations to ensure bad data cannot enter the persistence layer at that boundary

Hah I feel you on the hanami project search, I really enjoy the ideas of Hanami, but its small compared to rails obviously :)
Sebastjan Hribar
@sebastjan-hribar
I'm getting a strange error: Sequel::InvalidValue at ArgumentError: no time information in ""
When trying to create or read the affected entity. The entity has two DateTime attributes describing the start and end of contractual relationship. I can't find to many useful resources online. In migration, these fields are defined the same as the default ones for created_at and updated_at. Can someone shed some light on this?
Sebastjan Hribar
@sebastjan-hribar
slika.png
Sebastjan Hribar
@sebastjan-hribar

This is the error stack, the top of it, at least...

I've just moved db to postgres and it works fine. Any thoughts? I'd like to keep to sqlite for dev.

Kai Kuchenbecker
@kaikuchn
@calebbarde I think the guides do mention that validation at the model level is way too late and instead in Hanami it is idiomatic to validate at the boundary (i.e., in the action or an interactor to which the action delegates.) Should be mentioned somewhere here
So instead of accepting anything, and handling all possible values everywhere throughout a workflow and only validate when writing to the database, we first validate that inputs adhere to our expectations and then start the workflow which becomes so much simpler and less error prone.
As for an idiomatic example application.. I dunnow x(
There is https://snippets.hanamirb.org/ as a repository for example solutions to common problems
But it's still rather thin.. I really need to write more snippets x)
If in doubt just ask here and people will discuss solutions
Sebastjan Hribar
@sebastjan-hribar
RE my Sequel error: the same code with same gems works on one machine and not on another.
Kai Kuchenbecker
@kaikuchn
Different version of SQLite then?
Kai Kuchenbecker
@kaikuchn
Maybe one system uses 32bit version, other uses 64bit, or some such difference
Kai Kuchenbecker
@kaikuchn
Another possible cause is the data that's in the DBs (if any). If you look at the quirks of SQLite the flexible typing sticks out as a possible cause.. https://www.sqlite.org/quirks.html
I mean SQLite does not have a separate Datetime datatype and instead may store such data as text, int or real.
The error you receive looks like it's text in your case and that there's a row that simply contains no information
Sebastjan Hribar
@sebastjan-hribar
@kaikuchn I've checked everything above you mentioned and after applying the same DateTime format as described in the quirks and as used by the default created_by, it works on my machine. Before it didn't work even with date picker w/o any manual input. We'll probably move to postgres since we'll have a lot of dates and times to deal with. However, it's still unclear why different formats work differently on different machines.
Kai Kuchenbecker
@kaikuchn
I generally don't recommend using different databases between development, test, staging and production. Of course you're not going to employ a 25 node, sharded, highly available Cluster in development but one should still strive to have an environment as similar as reasonably possible between stages.
That way one can catch errors/problems early and many other problems that occur by having differences between environments can be circumvented.
Of course there's always cases where you may accept differences for convenience or other benefits. For instance we use Citus in production and when we started out migrating from MongoDB to Citus we also had 3-node clusters running on our local machines via VMs. But that was so goddamn slow, when we finished the migration and started to rarely touch the Code relating to Citus anymore we replaced the Cluster with a simple Postgres in development where we faked the Citus API (Citus is a Postgres extension which gives you horizontal scaling via sharding), accepting that if we change some SQL / calls to Citus we may not catch all errors, but trusting that our CI will, we made that tradeoff for a faster test-suite. (12 minutes -> 3 minutes, yeah VM networking overhead on OSX plus obviously a little more work by the DB, i think latency in production between nodes was less than 5ms consistenly but 100ms plus with our VMs)
Sebastjan Hribar
@sebastjan-hribar

@kaikuchn

I generally don't recommend using different databases between development, test, staging and production.

I agree, like I said, we're changing it :)

What are you using for alternatives to FactoryGirl? I've found references like cranky and blacksmith that don't dependent on AR.
Sebastjan Hribar
@sebastjan-hribar
I mean what are you all using as an alternative to FG? :)
Jeff Dickey
@jdickey
@sebastjan-hribar Have you taken a look at Fabrication? We switched to it from FactoryGirl when we were still a Rails shop, and it plays very nicely with Sequel and other ORMs as well.
Kai Kuchenbecker
@kaikuchn
Yeah, I've a high opinion of fabrication as well. It felt cleaner than FactoryBot to me.
Jeff Dickey
@jdickey
Agreed. A real pleasure to work with
...and only used the old name because that's what it was when we switched. I, too, prefer the new name, but oh well
Sebastjan Hribar
@sebastjan-hribar
Thank you @jdickey and @kaikuchn! It looks great :)
kristjan-brezovnik
@kristjan-brezovnik
Does anyone have any experience with the LESS preprocessor? I've followed the manual, but can't get it to work. I could also work with SASS or SCSS, if it's easier.
Kai Kuchenbecker
@kaikuchn
@kristjan-brezovnik sorry I've only worked with APIs. So I have no hands on setup experience with Hanami and Assets. But maybe I can still help. Could you share the relevant settings you've made in a gist? As well as what errors you get, if any?
Paweł Świątkowski
@katafrakt
kristjan-brezovnik
@kristjan-brezovnik
@katafrakt @kaikuchn Will retest as soon as @sebastjan-hribar migrates the server.
smarthouseprojectdotorg
@smarthouseprojectdotorg
Hi What's a Hanami way of rendering one or another template from the action? After coding in PHP I get used to program 'edit' and 'update' kind of actions like this. 'edit' action is programmed normally, it loads data and renders the template (default behaviour). 'update' action validates params, if validation fails, it renders 'edit' template with all the previously entered valid and invalid data in the fields; if params are valid, 'update' saves data to the db and renders/redirect to the index/list template.
Also found this hanami/view#128 Has this been implemented?
Paweł Świątkowski
@katafrakt
@smarthouseprojectdotorg I wrote this a long time ago, but I believe it still should work http://katafrakt.me/2015/08/14/different-views-for-one-action-in-lotus/
tl;dr
def call(params)
  @page = PageRepository.by_title(params[:id])
  if @page.nil?
    @page = Page.new(title: params[:id])
    self.body = Web::Views::Pages::NotFound.render(exposures)
  end
end
smarthouseprojectdotorg
@smarthouseprojectdotorg
Thanks @katafrakt , I found your article about it but as you said it looks like a magic and I agree. It seems to me there should be a more straightforward and standard approach for such a generic task.
smarthouseprojectdotorg
@smarthouseprojectdotorg
Following my own question above I have found these 4 articles which are very helpful and they answer all my questions above. Posting the links here as they may be a real help for those who started using Hanami not long time ago.
http://www.rottensoftware.com/create-record-in-hanami/
http://www.rottensoftware.com/update-record-in-hanami/
http://www.rottensoftware.com/validation_in_hanami/
http://www.rottensoftware.com/delete-records-in-hanami/
Maxim Dorofienko
@mdorfin
Hi there, how can I use already declared env variables in .env.development, I try to do something like this:
DATABASE_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$DATABASE_HOST/$POSTGRES_DB
Kai Kuchenbecker
@kaikuchn
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