Forum https://discourse.hanamirb.org – Code of Conduct http://hanamirb.org/community/#code-of-conduct
timriley on remove-flash-and-session-from-action
timriley on v2.0.0.alpha8
timriley on main
Prepare for v2.0.0.alpha8 (compare)
timriley on v2.0.0.alpha8
timriley on main
Prepare for v2.0.0.alpha8 (compare)
timriley on v2.0.0.alpha8
timriley on main
Prepare for v2.0.0.alpha8 (compare)
video.find(id)
I get both .location
and .location_id
to be nil and I can't do a consecutive location.find
because of that. How do I do this?
aggregate(:location).where(id: id).map_to(Video).one
in a single call — one of them doesn't seem to update parent object. or am I doing something wrong with this?
class VideoRepository < Hanami::Repository
associations do
belongs_to :location
has_one :video_info
end
def find_with_location(id)
aggregate(:location).where(id: id).map_to(Video).one
end
def find_with_info(id)
aggregate(:video_info).where(id: id).map_to(Video).one
end
def find_with_info_and_location(id) # this function doesn't populate location nor location_id
aggregate(:location).where(id: id).map_to(Video).one
aggregate(:video_info).where(id: id).map_to(Video).one
end
end
Hanami::Model.migration do
change do
create_table :videos do
primary_key :id
foreign_key :location_id, :locations, null: false
end
end
end
Hanami::Model.migration do
change do
create_table :locations do
primary_key :id
end
end
end
Hanami::Model.migration do
change do
create_table :video_infos do
primary_key :id
foreign_key :video_id, :videos, null: false, on_delete: :cascade
end
end
end
Hi everyone, first time here and with a question! I am trying to integrate Webpack (with Babel) for react using the hanami-webpack and hanami-assets gem, but I got into some trouble with import statements.
In my application.html.erb file, i use the <%= javascript 'index' %>
helper that points to my index.js file in assets, which works fine when it's pure Javascript and does not have any import statements. However, when i try to import React, it throws an error: "Uncaught SyntaxError: Cannot use import statement outside a module"
One of the solutions i found online is to put "type"="module"
to package.json to ensure that all .js files are seen as modules and not CommonJS - I tried doing it, but it lead to another error with my Webpack.config.js file, which is using 'require' instead of import. I changed the file extension to Webpack.config.cjs, which resolved the error the server was throwing, but I am still stuck with 'Cannot use import statement outside of module'
Does anyone know how to solve this? Is there a good example of how to integrate React with Hanami? Thanks!
Hey everyone, hope you are enjoying your holidays - just fyi, after several days of tinkering with trying to integrate React as the frontend with Hanami, I came up with a basic setup that I am hoping is useful to see for anyone who is new and would like to do the same thing - I gave up on Webpack because it was unnecessarily complicated, could not get hot reload to work and the compile times were pretty long - so I used ESbuild instead. Here is a repo with a template you can use: https://github.com/glemin5011/react_on_hanami
Just be aware that it does not have any installer or anything, so things such as .env files etc. are not really transferrable to new projects - this repo is more of a demo / guide
Edit: This is for Hanami v1.3.5
Hey, I have this code in the views/application.rb
:
def current_user_roles
UserRepository.new.find(session[:current_user]).roles
end
where the current_user is the user's ID. However, the view has no access to the session
. How can I bypass this? The use case is limiting the displayed items as per user roles.
bundle
when working with the hanami 2 template...for some reason, mine is stuck and does not process beyond this point (ongoing now for over half an hour)...
Running bundle install - this may take a few minutes
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/hanami/hanami.git
`
Hey Hanami experts, I've just cloned the template repo for Hanami 2, followed the steps for setting up, but when it came time to setup a new migration, I ran into the following error:
`method_missing': undefined method `session_secret' for #<Hanami::Application::Settings:0x000055af322964b8 @config=#<Dry::Configurable::Config values={}>> (NoMethodError)
What could I be doing wrong?
Hey Hanami experts, I've just cloned the template repo for Hanami 2, followed the steps for setting up, but when it came time to setup a new migration, I ran into the following error:
`method_missing': undefined method `session_secret' for #<Hanami::Application::Settings:0x000055af322964b8 @config=#<Dry::Configurable::Config values={}>> (NoMethodError)
What could I be doing wrong?
By the way, I've already setup a secret string in the .env file
Hi, I've encountered another issue when deploying to production. I'm deploying with docker on client's server and I have bundle exec hanami assets precompile
in my docker compose right before starting the server. However, not all assets are in the public
folder.
If I run precompile before the build and don't run precompile with compose then I get the Internal Server Error
.
If I run precompile in a running container the assets are again not served.
I have the option to serve static assets set to true in my .env.production
.
As per usual, what am I doing wrong?
Is it possible to have raw sql like this:
def find_by_segment_match(source_text_for_lookup, source_lang)
segments
.read("set pg_trgm.similarity_threshold TO 0.4;
SELECT *, SIMILARITY(segments.content, '#{source_text_for_lookup}') AS similarity
FROM segments
JOIN translation_records
ON segments.id = translation_records.source_segment_id
LEFT JOIN segments AS target_segments
ON translation_records.target_segment_id = target_segments.id
WHERE segments.language_id = #{source_lang} AND segments.content % '#{source_text_for_lookup}'
ORDER BY segments.content <-> '#{source_text_for_lookup}';").map_to(Segment)
end
and to map it to a entity, in my case Segment
. I wanted to use raw sql since I have trouble implementing the LEFT JOIN
with Hanami.
gem
?
Dry::Struct
.
Hi , I've ran this migration, which completed without errors, but when I run the server below:
Hanami::Model.migration do
change do
alter_table :segments do
add_column :ts_content1, :tsvector, generated_always_as: [to_tsvector: [:simple, :content]]
end
end
end
Error:
Hanami::Model::Error: missing attributes in ROM::Relation::Name(segments) schema: :ts_content1
How can I debug this?
Hi all. I am wondering if anyone has done/is doing application-level encryption à la Active Record Encryption https://guides.rubyonrails.org/active_record_encryption.html
I am looking to add most of the feature set of AR Encryption to our application.