Activity
Thoughts on how to use Meilisearch on Heroku?
Posted in Custom Image Analyzer
I have a custom ActiveStorage analyzer that (will) exact a bit more metadata out of an image and save it in ActiveStorage (i.e.: camera, shutter, etc...) For simplicity sake, the metadata method has a basic hash. Here's what I have:
- I add ExifAnalyzer to
lib/analyzers/exif_analyzer.rb
- Next, created file called
active_storage_analyzers.rb
in/config
withRails.application.config.active_storage.Analyzers.prepend ExifAnalyzer
- In my application.rb I make sure the class is loaded
config.autoload_paths += %W[#{config.root}/lib]
- Restarted the app
- I receive this error on startup. Any ideas would be welcome.
uninitialized constant ExifAnalyzer (NameError) Rails.application.config.active_storage.Analyzers.prepend ExifAnalyzer
Might be helpful. -- Rails 7.0.3, Ruby 3.1.2, Vips
ExifAnalyzer
lib/analyzers/exif_analyzer.rb
class ExifAnalyzer < ActiveStorage::Analyzer
require 'exifr/jpeg'
def self.accept?(blob)
['image/jpg', 'image/jpeg'].include? blob.content_type
end
def metadata
{ test: true }
end
end
I am hoping someone might be able to shed some light on this issue. I have this JS code (below) located in packs -> application.js. It grabs the class name and adds additional class. The division's names are temp placeholders. When running in development mode, it works great in all browsers (Chrome, FF, Safari). When tested in a production environment, it works only in FF and Safari. Not in Chrome. Hmmm.... I’ve tried moving the code out of Webpacker (application.js) and received the same results.
The only error Chrome gives is: Uncaught TypeError: Cannot read properties of null (reading 'classList')
I’m certainly open to suggestions, ideas, improvements.
window.addEventListener("load", function (event) {
var divisions = ['one', 'two', 'three', 'four', 'five', 'six']
divisions.forEach(function (item) {
var director_office = document.getElementById(item).getElementsByClassName('google-visualization-orgchart-table')
director_office.item(0).classList.add('table')
})
})
Rails: 6.0.4.4
Ruby: 2.7.3
Posted in ActionText / Trix Editor
I'm working on upgrading an app from Rails 6.1.x to 7.0.1 with esBuild for JS. I am having trouble getting ActionText, in particular the Trix editor toolbar, to work correctly when running in production
environment? What's odd, if I add this:
@import 'trix/dist/trix.css';
to application.bootstrap.scss
it works when in development
using bin/dev
but not in production
.
I found this issue on GitHub, which is more or less the same. Wondering if anyone else has experienced this as well.
https://github.com/rails/rails/issues/43441
Posted in Rails 7.0.0rc1
Glad, I could help. :)
Echoing the bootstrap-icon comment. Been playing with Rails 7 with esbuild and I can't seem to get it to work.
Posted in Rails 7.0.0rc1
Follow up on my own post:
Uncomment this in the Gemfile:
gem "sassc-rails", "~> 2.1"
ran
bundle update
bin/dev
The server started successfully. :)
Looks like this gem was commented out in Rails 7 alpha2 default new builds.
Posted in Rails 7.0.0rc1
Been playing around with Rails 7 aphla2 and yesterday they released an RC version. In my Rails 7 test app, which was previously running alpha2, ran bundle update
it updated everything to the RC version. Great! Starting the app in the Dev environment bin/dev
generates the error below. Anyone else experiencing this? Also, tried using Ruby v3.0.2 and received the same error.
/Users/xxxxx/.rvm/gems/ruby-2.7.1/gems/railties-7.0.0.rc1/lib/rails/railtie/configuration.rb:96:in `method_missing': undefined method `assets' for #<Rails::Application::Configuration:0x00007f79da9309a8> (NoMethodError)
09:14:56 web.1 | Did you mean? asset_host
Posted in Esbuild
What it looks like is any sort of "image (jpg, SVG, maybe fonts, etc...)" reference in a CSS file, for example, background-image URL("someimage.jpg")
is not being picked up / path issue.?. Hence why Bootstrap Icons are not working.
Posted in Esbuild
Thanks, Chris. Tried setting config.assets.css_compressor = :sass
to nil
and no luck. Even tried enabling the:sass option, recompiled the app. No luck. I noticed this is happening with another Yarn package I'm using that has images (SVG) in the node_modules dir. I'm wondering if something should be added to the manifest.is file?
Posted in Esbuild
I'm trying to get away from Webpacker... Installed the gem JSBundling on a Rails 6.0.1.x app, followed the setup procedures to use EsBuild, and it worked. Got BootStrap 5 working with the guidance from your screencast. Thanks! Installed bootstrap icons with Yarn. Added: @import bootstrap-icons/font/bootstrap-icons
to my application.bootstrap.scss file. Fired up the dev server - bin/dev
- works perfectly. Icons!!! When I test in the production setting (rails s -e production), it's broken. I've tried RAILS_ENV=production rake assets:precompile`` without any success. It does work if I change this config setting in the Config -> Environment -> Production
config.assets.compile = false ``` to true. Thoughts on how to remedy this?
Thanks Chris for the response. Sorry for the delay, I had pivot to another project for small feature update. I feel I'm close to solving this issue, but I'm drawing a blank on the best approach to submit a form that can update multiple rows / (or ids). I'm using SimpleForm and the view/_form looks like this:
simple_form_for(@author_article, url: article_author_articles_path, html: {class: 'form-group'}) do |f|
- if @article.errors.any?
= render partial: "partials/error_messages", locals: {object: @article}
- @authors.each do |i|
.field.text-capitalize
= f.label i.fullname
= f.hidden_field :author_ids
.field
- i.author_articles.where("author_id = ?", i.id).where("article_id = ?", @article.id).each do |o|
= f.input :author_sequence_ids,
collection: @author_sequences,
selected: o.author_sequence_id,
label: false,
prompt: "Choose Something"
.actions
%p= f.submit 'Save', class: 'btn btn-sm btn-primary text-center'
The form appears like this in the view.
Chris Rock <select><option "Choose Something ...
Jimmy Fallen <select><option First ... selected
Chuck Norris <select<option Second ... selected
<button>Save ...
And of course in the controller (AuthorArticlesController) I'm permitting author_sequence_ids: [], author_ids: [], article_id
The issue I'm having is the dropdown menu does not know the author. Any advice you or anyone else would be welcome!
Posted in Running Yarn offline
I have a production server Running Rails 6 (latest version) that is extremely locked down. I don't manage the infrastructure surrounding (firewalls, IPs, etc...) the server. Only a few things are allowed to connect and pass through. One of the challenges I'm facing is Yarn. Yarn seems to be tightly integrated into Rails 6, this is fine if the server can connect to the Yarn package repo but becomes a problem/nuisance when it can't. I've tried following this from Yarn without any success.
https://classic.yarnpkg.com/blog/2016/11/24/offline-mirror/
Whenever I run Yarn install --check-files
, it returns 'can't connect ... ' or something like it, which is expected. If you need to precompile assets, open the console (rails c), and so on Yarn wants to run.
Any thoughts/guidance anyone can provide in managing Yarn on this machine would welcome.
I have a view (show) that display's an Article. The Article has several Author[s]. The Article and Author models look like this:
Associations:
Article Model
has_many author_articles
has_many articles, through: :author_articles
Author Model
has_many author_articles
has_many author, through: :author_articles
AuthorArticle Model
belongs_to article
belongs_to author
The join table (AuthorArticle) contains an article, author id columns, and another column called position_id. The Position model is also a has_many through. It looks like this:
Associations:
Position Model
has_many author_articles
has_many positions, through: :author_articles
Author Model
has_many author_articles
has_many author, through: :author_articles
AuthorArticle Model
belongs_to article
belongs_to author
belongs_to position
Here's what I would like to do and I am not exactly sure how to implement it. I would like to click on the author's name from the article show view, open a modal (already done) and have a form (SimpleForm) where the user can select a position (first, second, third, etc...) and press submit. The order of the author is important. Yes, there can be several "first/lead" authors. The form post would update the join table (AuthorArticle) position_id column with the position selected. Authors are added when a new article is created or updated.
Does this make sense? Let me know if you need more context? Something doesn't feel right about this approach and I'm open to suggestions/feedback/ideas.
Thanks!
Let's say we have a Rails project operating on the domain https://hello.world.com. The way the organization's infrastructure is set up, https://hello.world.com gets proxied into a new URL called - https://my.companies.server.com/hello . When I start the server with Rails s -e production and navigate my browser to https://my.companies.server.com/hello, all the CSS, assets, JS is broken. After some research I changed this config:
config.action_controller.asset_host = 'http://hello.world.com' and the CSS, JS, and assets seem to be working again. Great. One thing that's certainly not right is the links / main navigation (routes). For example, when navigating to any page in the browser, for example, https://my.companies.server.com/about, I get a 404. Seems like there should be a "pass-through" when a request comes in it gets mapped it to https://hello.world/about? Does this make sense? I could use some assistance. What's the best approach here?
My Setup
Rails 6.x.x
Ruby 2.7.x
Nginx
Thanks!
I would like to get everyone's take on what are is the best practice for storing DB usernames/passwords, API keys, Contstants, Etc... Should they be stored in config/environments/ then in test, development production accordingly? Some of these files do end up in verstion control. Thoughts?