Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Arvy Petil
@alnpetil
image.png
I've included it and activesupport (since it's looking for it when I run tests) and now I'm getting that error which I'm not familiar with
Kai Kuchenbecker
@kaikuchn
Does the error go away if you don't include activesupport and/or light-service?
The constant in question recently came up when there was some issue with tilt (see rtomayko/tilt#347), so that's also making me a little suspicious. If you're using hanami-utils 1.3.4 maybe the changed lookup has some side-effects? If you're not using 1.3.4 try upgrading to it.
Kai Kuchenbecker
@kaikuchn
@jodosha you've digged into that recently, so maybe you have some insights as to what might be going on there. Here's the transcribed error @alnpetil is experiencing:
 1) Web::View::ApplicationLayout contains application name
    Failure/Error: let(:rendered) { layout.render }

    NameError:
      uninitialized constant Hanami::View::Rendering::NullView::TOPOBJECT
      Did you mean?  Object
    # ./apps/web/templates/application.html.erb:-7:in `method_missing`
Arvy Petil
@alnpetil
Yes it does go away, but ActiveSupport is a dependency, unfortunately, for light-service. I really liked that gem for chaining service objects and was planning to use the same to wrap the interactors I had. I was using Hanami v1.3.1
Arvy Petil
@alnpetil
Updated hanami-utils from 1.3.1 to 1.3.3 and no more errors! I'll let you know after I do more tests. Thank you @kaikuchn
Wonder if the issue you tilt issue is related
glaszig
@glaszig

@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

upvote for customizable inferred schema. i looked into it but as far as i saw it's not an easy change in hanami-model.

Luca Guidi
@jodosha
https://twitter.com/hanamirb/status/1182637973759823874 hanami-assets v1.3.4 - This version allows to precompile assets on Windows.
@kaikuchn @alnpetil That problem was caused by latest tilt. See https://twitter.com/hanamirb/status/1177498984551612416
Sebastjan Hribar
@sebastjan-hribar
Hi, I have a question regarding nested forms. I am building a form for 3 entities. For example, I have A - source string, B - target string and C - translation record. The main form is within the template for the C entity. By submitting the form all three should be created. What would be the best way to approach this? Can I reference the A and B from within the form for C? I can only find the nested fields reference in the guides under form helpers.
Sebastjan Hribar
@sebastjan-hribar
I guess this would be equivalent to fields_for in Rails. Although, another problem I have is also the fact that the C must contain IDs from A and B.
Sebastjan Hribar
@sebastjan-hribar
To add a bit more context to my question above. The goal is to build a translation editor interface, effectively having one template for managing multiple entities. What would the best practice be? I'm thinking of having a template for /translation_record (possibly /translation_editor) and then moving the logic to an interactor to handle the creation of all entities and finally calling the interactor in the translation_recordaction. Can someone point me in the right direction to build such more complex scenarios?
Kai Kuchenbecker
@kaikuchn
Can you show us some example code? Or maybe some pseudo code of what you'd like to achieve?
Sebastjan Hribar
@sebastjan-hribar
@kaikuchn Sure, I'll draft some pseudo code for the files and code I think would correspond for such scenario.
EGORIDI
@EGORIDI
Hi folks. I'm getting started with the tutorial and could'nt migrate the database schema. When I try I get a "SQLite3 SQLException: no such table: schema_migrations: SELECT NULL AS 'nil' FROM schema_migrations LIMIT 1" as well as " SQLite3::SQLException: no such table: schema_info: SELECT NULL AS 'nil' FROM schema_info LIMIT 1".
When I try to prepare the database with "HANAMI_ENV=test bundle exec hanami db prepare " I get "HANAMI_ENV=test : The term 'HANAMI_ENV=test' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again." Does anyone know how can I get through it?
Paweł Świątkowski
@katafrakt
@EGORIDI Are you using in-memory SQLite db? IIRC it does not work now, you should use persisted one.
Kai Kuchenbecker
@kaikuchn

When I try I get a "SQLite3 SQLException: no such table: schema_migrations: SELECT NULL AS 'nil' FROM schema_migrations LIMIT 1" as well as " SQLite3::SQLException: no such table: schema_info: SELECT NULL AS 'nil' FROM schema_info LIMIT 1".

It's okay for that table to not exist, it should simply be created subsequently. Sadly, this "error" is printed to the console and confuses people.
What @katafrakt said still applies.

EGORIDI
@EGORIDI
Thanks, I'll try it.
Emir Fernandes da Ponte
@EmirFernandes_gitlab
Hello!
Kai Kuchenbecker
@kaikuchn
Hi
Danny Santos
@DannySantos
Does anybody have any advice on clearing the params after an AJAX request? Because the template that gets rendered comes directly from (for example) the create view/controller, it still has the params that were submitted in the post request. This causes issues when, for example, re-rendering a form upon success. You don’t want the form builder to attempt to fill in the fields with the params.
Kai Kuchenbecker
@kaikuchn
Redirect on success instead of re-rendering the form. That way the user can even refresh the page without triggering a post again.
Danny Santos
@DannySantos
@kaikuchn but doesn’t that somewhat defeat the point of AJAX? The great benefit of asynchronous apps is that we can create a seamless user experience as well as make the app more efficient by not having to reload the page or redirect.
Kai Kuchenbecker
@kaikuchn
I'm not entirely sure what you're doing or trying to accomplish. Are you sending chunks of HTML and interpolate them into your existing DOM? If all you want to do after submitting a form via ajax is to clear it, why not just clear it client-side? Server could just give you a success response without a body in that case.
Again, not really sure what you're doing.
Danny Santos
@DannySantos
Generally what my AJAX requests do is either return a failure or success. If it’s a failure I simply use JS to display a notification. Upon success however, I generally display a notification and also re-render a section of the page, ususally by assigning the contents of a partial to a JSON object and then replacing the page section with JS.
smarthouseprojectdotorg
@smarthouseprojectdotorg
Hi I'm new to Hanami, is it a right place to ask questions? :)
smarthouseprojectdotorg
@smarthouseprojectdotorg

Got a problem with using repositories and the code below returns undefined method `all' for ROM::Relation::Composite It seems query methods are not chainable?

class UsersRepository < Hanami::Repository
def yesterday_and_older
users.where{ created_at < (DateTime.now() - 1.0) }.all
end
end

Could someone shed a light on it?

unleashy
@unleashy
@EGORIDI by the way, this error "HANAMI_ENV=test : The term 'HANAMI_ENV=test' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again." is just a Windows weirdness; you can't set environment variables before the command like you can in linux
the workaround is to set the env var before then unset it after:
> set HANAMI_ENV=test
> (do hanami stuff for the test env)
> set HANAMI_ENV=
(yes, it's extremely annoying)
maybe the hanami docs need to be updated to tell Windows users about that...
Sebastjan Hribar
@sebastjan-hribar
@smarthouseprojectdotorg You don't need/can't call the all method in your case. It's implemented so you can call allon the repository like UserRepository.new.alland it returns all entities. Your yesterday_and_older will return all entities corresponding to your condition.
Sebastjan Hribar
@sebastjan-hribar

I have a problem with updating a record. This is the very basic update action:

module Godmode
  module Controllers
    module ContactPersons
      class Update
        include Godmode::Action

        def call(params)
          @contact_person = ContactPersonRepository.new.update(params[:id], params[:contact_person])
          redirect_to "/godmode/contact_persons"
        end
      end
    end
  end
end

Up until I hit the submit button everything works. The updated params show up in the server log as well.
I also notice that no matter what I use to redirect to, it always goes to http://localhost:2300/godmode/contact_persons?id=3except for the 3 part of course.

In my routes I have only
resources :clients
resources :contact_persons
Sebastjan Hribar
@sebastjan-hribar
The entity is not updated and the params actually are not passed to the action.
Sebastjan Hribar
@sebastjan-hribar
I've tried whitelisting the params, but no luck. Any ideas how to debug it or what I'm doing wrong?
Sebastjan Hribar
@sebastjan-hribar

The params.inspect in my update action, called by the spec, returns:

#<Godmode::Controllers::ContactPersons::Update::Params:0x000055fe732aa7c0 @env={"REQUEST_METHOD"=>"GET"}, @input={}, @result=#<Dry::Validation::Result output={} errors={:id=>["is missing"], :contact_person=>["is missing"]}>, @params={}, @errors={:id=>["is missing"], :contact_person=>["is missing"]}>

It confirms nothing gets to the action, but why is the request method GET?

Sebastjan Hribar
@sebastjan-hribar
Also, create, show and index all work fine.
Paweł Świątkowski
@katafrakt
@sebastjan-hribar I would start with adding some validation and checking if it passes for params
You say params are not passed to the action. Then how does the code that leads to execution of this action looks? Also what is in Godmode::Action?
Sebastjan Hribar
@sebastjan-hribar
@katafrakt Hi, here's a gist of the relevant code. I've followed same patterns as in my previous app, the main difference being is that here are many apps (Godmode being one of them) under the main project tmsr. The other app only has the webapp.
https://gist.github.com/sebastjan-hribar/76bcd650c01837f67ffb143e3470d839
Paweł Świątkowski
@katafrakt
@sebastjan-hribar form_for :contact_person, routes.contact_persons_path(id: contact_person.id) - why contact_persons_path and not contact_person_path? You're probably calling different action (create perhaps?). Or I don't understand your routing ;)
Kai Kuchenbecker
@kaikuchn

Generally what my AJAX requests do is either return a failure or success. If it’s a failure I simply use JS to display a notification. Upon success however, I generally display a notification and also re-render a section of the page, ususally by assigning the contents of a partial to a JSON object and then replacing the page section with JS.

I thought as much. If that is how you want to handle things, then you will have to make sure that you don't pass the request params to the rendering of the partial, just replace it with an empty hash I guess.

@smarthouseprojectdotorg Yes, this is the right place. Welcome to Hanami!
As Sebastjan pointed out all gives you a result set, which is all records in your repository. If you have a look at the guides you will find out WHY you cannot chain methods. This is intentional! In general I recommend perusal of the guides since Hanami is different from what, say, a Rails Developer is used to.
Sebastjan Hribar
@sebastjan-hribar
@katafrakt I knew it has to be something stupid I did and you found it :smile: Thank you!
Works like a charm now
smarthouseprojectdotorg
@smarthouseprojectdotorg
@sebastjan-hribar @kaikuchn
Thank you! So using where() or where{} gives the result set right away and then I can use it or say .delete it. Does it sound correct?
Danny Santos
@DannySantos

@kaikuchn That’s one of two ideas we’ve been working with. We implemented it as a view method on :js views:

def params
  return @_params if @_params

  @_params = locals[:params].dup
  @_params.to_h.keys.each{ |k| @_params.to_h.delete(k) }
  @_params
end

The other idea we’re playing with is adding an option to the form_for method which tells it not to prioritise the params. There’s a discussion about it going on in this issue if anyone is interested:

hanami/helpers#149