2,330 Experience
23 Lessons Completed
0 Questions Solved


Posted in Introduction to Importing from CSV Discussion

Late to the party and all that but if anybody is looking to seed their project database from a CSV file, the is what I enter in my seed.rb file(s):

CSV.read(Rails.root.join('lib', 'seeds', 'file_with_data_to_import.csv'), headers: true).each do |row|
t = ImportingModelName.create(row.to_hash)
puts "#{t.name}, #{t.some_other_attribute} saved"

// Optional part
puts "There are now #{ImportingModelName.count} rows in your ImportingModelName database table."

The same can be used in a Rake Task file as per Chris’s video. It assumes that the CSV file has header row but, for a scheduled task, you could take care of those on the fly as per the video.

Performance-wise, it works rather well. For example, I had to seed a project database with a bit fewer than 25,000 records, which took about 2 minutes on my development machine. Each record had 40 columns, 20 of which had to be validated, and I had to modify the text case of the content in 6 of the columns.

Hope this helps someone.

From my (fairly limited) experience, Hotwire may be easier to get started with but StimulusReflex is, at least at this point, more powerful and flexible, and perhaps more ambitious. Depending on what you plan on building, either could be sufficient/appropriate but you could combine them as well.

This allows you to have different functionality based on the device type a user access your app from. For example, you could use Hotwire/Turbo to show both a list of records and a detail on the same screen when the app is accessed/viewed from a desktop browser, and do more conventional list > detail individual page views on a mobile phone due to screen size limitations and, for example, inability to hover over links, etc.

The responsive CSS would still be in play for styling and what is shown and how, but you would also be able to use different style sheets altogether based on the device type any single user uses to access the app.

Posted in Contact form that sends email directly from the page

Hi Kyle,

Here are examples that may help you get the form working:

You can also share your code, if you feel comfortable, for additional help.

Based on the pre- version of Rails, I found Carrierwave to be more suitable for apps where I need to generate multiple-size versions of an image on upload that I may want to use outside the app itself (the ActiveStorage has not worked quite as well in a couple of apps of this type I built). Other than that, I find ActiveStorage to be rather nice, and it’s likely to get better in the future.

Have not had to do a migration from Carrierwave to ActiveStorage but, based on the available documentation, it looks doable but would require a lot of work so it may be better if one stuck to Carrierwave if that’s what they already do.

Knowing what kind of app you are building (in the most general terms) would help recommend one or the other.

Posted in How to use ActionText in Rails 6 Discussion

Not yet. The CSS approach would not have worked in this specific case so I treid mucking about in the source code but gave up as I didn’t feel like having to reivist the issue each time a Rails update rolls around.

I eventually settled on using Redactor as it gave me the control I needed for this project. Not as straightforward as ActionText though.

I do have some ideas on how to address the Trix editor configuration but have not had time to explore them. Will post here when I have something working.

I looked at both the ActionText and Trix documentation and could not find anything on how to disable/remove formatting tools and disable file uploads for ActionText.

For the project I am working on, I need only text formatting (bold, italic, lists, etc.) but not file uploads and hyperlinks. I considered dealing with hyperlinks via Rails content formatting options (rendering them as text) but was hoping for a bit more elegant approach before going down that route. As for blocking uploads, no idea whether that is possible while also using ActionText.

Has anybody deal with this alredy or does anybody know where I could look up more information?

Thanks in advance.

Posted in How to use ActionText in Rails 6 Discussion

Is there a way to limit the formatting options in the Trix editor? For example, if I don’t want users to enter links or upload images, is there a way I can configure the editor so that those options are disabled and not just not shown (I can do the latter via CSS).

Posted in How to use Action Mailbox in Rails 6 Discussion

How difficult, assuming it’s possible, would it be to adjust this for receiving replies via SMS (to use the episode’s example)?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.