Tommy

Joined

530 Experience
4 Lessons Completed
0 Questions Solved

Activity

I have a site where the user can apply a combination of multiple filters.

To improve the SEO on the site I would like to have the URL in a human-readable format when filters are applied.

I would like the URL to be:
example.com/stadiums-in-england-or-spain-with-grass-and-capacity-of-more-than-20000

Instead of:
example.com/country=england,spain&surface=grass&with_capacity_of_more_than=20000

This is something that I've seen on NomadList where for example, if the user applies the filter 'walkable' and 'Europe the generated URL will be
https://nomadlist.com/walkable-places-in-europe

Anyone here has any idea on how to build this?

I use the Shrine gem to upload images to AWS S3 from my Rails app.

Now I’m trying to load the asset trough Cloudflare CDN, but then my images fail to load.

Here’s my attempt to implement this

  1. Created an AWS S3 bucket with name cdn.myrealdomain.com
  2. Created a CNAME record in Cloudflare set to: Name: cdn and Host: cdn.myrealdomain.com.s3.eu-north-1.amazonaws.com



Now I can access the XLM for my bucket both trough
**s3.eu-north-1.amazonaws.com/cdn.myrealdomain.com
* and trough
cdn.myrealdomain.com/ *

3. Then I added this line to my shrine.rb to set the URL HOST to my cdn.myrealdomain.com



plugin :url_options, store: { host: "https://cdn.myrealdomain.com" }


4) Now. when I start my rail server, all image assets fail to load.
If I copy image address and paste it into my browser it shows error
SignatureDoesNotMatch

**Here's the URL generated by the image_tag helper in rails (that is NOT working)**



https://cdn.myrealdomain.com/store/48a9048cb8e5f31306417e2a1a3c7bf3.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ5I6Z37AW6G7Q5PQ%2F20201113%2Feu-north-1%2Fs3%2Faws4_request&X-Amz-Date=20201113T121155Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=1c82f8c15fcfbfe59d24a74a560a5837696a10ac49cdadeaa971b6565700faa8




However if I delete the trailing characters after
https://cdn.myrealdomain.com/store/48a9048cb8e5f31306417e2a1a3c7bf3.png
The image load properly.



Any suggestions to resolve this would be very much appreciated!

Posted in Import into administrate?

Ah, that solved my issue. Now it works! :)

Thank you so much for your help and these fantastic resources!

Posted in Import into administrate?

Thanks for your reply @Chris!

Been looking at your tutorials for Shrine and CSV imports. And trying to get this to work, using and rake import task. But I'm getting an error when I run the rake task.

rake aborted!
ArgumentError: bad argument (expected URI object or URI string)

Here's my code. Any help to this, would be very much appreciated.

** /lib/tasks/import.rake **

require 'csv'
namespace :import do
desc "Import stadiums from csv"
task stadiums: :environment do
filename = File.join Rails.root, "stadiums.csv"
counter = 0

    CSV.foreach(filename, headers: true) do |row|
    stadium = Stadium.create(name: row["name"],city: row["city"],image: Shrine.remote_url(row["coverphoto"]))

    counter += 1 if stadium.persisted?
    end
    puts "Imported #{counter} stadiums"
    end
    end


** app/uploaders/image_uploaders.rb
 **
class ImageUploader < Shrine
Attacher.validate do
validate_size 1..5*1024*1024
validate_mime_type %w[image/jpeg image/png image/webp image/tiff]
validate_extension %w[jpg jpeg png webp tiff tif]
end
end

/shrine.rb

require "shrine"
require "shrine/storage/file_system"
require "shrine/storage/memory"
require "shrine/storage/s3"

if Rails.env.test?
Shrine.storages = {
cache: Shrine::Storage::Memory.new, # temporary
store: Shrine::Storage::Memory.new, # permanent
}
else
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), # permanent
}
end

And in my stadiums_controller I’ve added :image as param.
def stadium_params
params.require(:stadium).permit(:name, :city, :image)
end

Posted in Import into administrate?

Hi, I think Jumpstart looks really promising and I thinking about using it for my next project.

But I also had some concerns about importing data to my app. I'm used to be doing import via the active-admin-import gem. In the application I'm working on I need to import lots of CSV-files and some of the columns include remote-links to images that I want to import and store on my app/cloud storage.

Is there any Go Rails Episode covering uploading images from CSV files? I can't find much information on that matter.