Activestorage

50 views
Skip to first unread message

Gloufy

unread,
Mar 16, 2020, 7:23:32 PM3/16/20
to ActiveScaffold : Ruby on Rails Gem
Hi Sergio,

I'm using active storage plugin bridge in active scaffold.
But I don't have the thumbnail in form "mode" juste the name of the file. With dragonfly I have the thumbnail, do you know why ?

How to persist file upload fields after a rails validation error with activestorage and activescaffold https://stackoverflow.com/questions/15680484/how-to-persist-file-upload-fields-after-a-rails-validation-error


Thank you for your help

Gloufy

Sergio Cambra

unread,
Mar 17, 2020, 7:47:06 AM3/17/20
to ActiveScaffold : Ruby on Rails Gem

ActiveStorage bridge was a contribution, I didn't write it, I haven't tried ActiveStorage yet. However, I can see form_ui is calling helper for list and show actions to display content, as other bridges related to file upload do.

 

Form_ui has this line:

 

content = active_scaffold_column_active_storage_has_one(record, column) if active_storage.attached?

 

That line display content with same helper as list and show. And that helper, active_scaffold_column_active_storage_has_one method has this line:

 

attachment.attached? ? link_for_attachment(attachment) : nil

 

But link_for_attachment doesn't display thumbnail:

 

def link_for_attachment(attachment)

link_to(attachment.filename, rails_blob_url(attachment, disposition: 'attachment'), target: '_blank')

end

 

 

I think that helper method must be changed to display thumbnail, as other bridges do. Carrierwave bridge display thumbnail, and thumbnail style name can be changed in bridge config. Paperclip do it in same way. Dragonfly do it in same way too, but it allows to set :thumb option in column's options. What is code to display thumbnail with ActiveStorage?

--
You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activescaffol...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/activescaffold/3bf5a081-ede1-4402-bf52-1f518063b4af%40googlegroups.com.



Gloufy

unread,
Mar 17, 2020, 1:18:50 PM3/17/20
to ActiveScaffold : Ruby on Rails Gem
something like that  image_tag user.avatar.variant(resize_to_limit: [100, 100])

Where can I override the helper link_for_attachment(attachment) ? 

and for the other question do you have a clue how to do it ? (

How to persist file upload fields after a rails validation error with activestorage and activescaffold ? )

To unsubscribe from this group and stop receiving emails from it, send an email to activescaffold+unsubscribe@googlegroups.com.

Sergio Cambra

unread,
Mar 18, 2020, 8:25:34 AM3/18/20
to ActiveScaffold : Ruby on Rails Gem, Gloufy

I think you can override that helper in your controller helper, or ApplicationHelper. I think it should work as dragonfly does, there should be a thumbnail_variant setting in ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers, default to something like {resize_to_limit: [nil, 30]} to use same values as dragonfly bridge.

 

I have added this to master branch. However, I have checked docs for activestorage in rails 5.2 and I don't see resize_to_limit option, did it changed in 6.0?

 

I'm not sure what you want about the other question. Do you want to keep uploaded file so user doesn't need to upload it again? Or do you want to have input file prefilled so user doesn't have to browse file to upload again? The former, I don't know, does it rails save attachment into active_storage_blobs table? It could be orphaned if form is not submitted again. The latter, I think it isn't possible, I think browser doesn't allow to set value attribute for input file tag.

To unsubscribe from this group and stop receiving emails from it, send an email to activescaffol...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails Gem" group.

To unsubscribe from this group and stop receiving emails from it, send an email to activescaffol...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/activescaffold/cc2b370b-1a3a-4ae1-91bf-ff91e0ae92a2%40googlegroups.com.



Sergio Cambra

unread,
Mar 18, 2020, 8:29:17 AM3/18/20
to ActiveScaffold : Ruby on Rails Gem, Gloufy, 'Sergio Cambra' via ActiveScaffold : Ruby on Rails Gem

A way could be using JS to display error messages instead of replacing form, although fields won't get any class to highlight them with CSS, unless JS make some changes to existing fields too.

Gloufy

unread,
Dec 30, 2021, 1:03:47 PM12/30/21
to ActiveScaffold : Ruby on Rails Gem
Hi Sergio !

Where I can exactly orrveride ? I didn't manage to do what.


module ActiveScaffold

module Bridges


class ActiveStorage


module ActiveStorageBridgeHelpers


mattr_accessor :thumbnail_variant


self.thumbnail_variant = {resize_to_limit: [nil, 30]} to
{resize_to_limit: [nil, 350]}

Sergio Cambra

unread,
Jan 2, 2022, 7:28:14 PM1/2/22
to ActiveScaffold : Ruby on Rails Gem
I think you shouldn't define mattr accessor, it's already defined.

I think it should work with only one line in initializer:

ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers.thumbnail_variant = {resize_to_limit: [nil, 350]}


Gloufy

unread,
Jan 13, 2022, 3:16:28 PM1/13/22
to ActiveScaffold : Ruby on Rails Gem
i'v got a error config/initializers/active_scaffold.rb:3:in `<main>': uninitialized constant ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers (NameError)

Did you mean?  ActiveStorageVariant

Sergio Cambra

unread,
Jan 17, 2022, 9:33:05 AM1/17/22
to ActiveScaffold : Ruby on Rails Gem
No, I meant that module defined in lib/active_scaffold/bridges/active_storage/
active_storage_helpers.rb, which has thumbnail_variant mattr accessor.

I was out of home and I couldn't test it before answering. I have tested now
and ActiveStorageBridgeHelpers is not loaded yet when initializer runs. You
could add require 'active_scaffold/bridges/active_storage/
active_storage_helpers' in initializer before that line, but I guess it should
be fixed in ActiveScaffold. I could add autoload lines in lib/active_scaffold/
bridges/active_storage.rb, but I guess it's better to define the setting in
ActiveScaffold::Bridges::ActiveStorage class.

I have changed thumbnail_variant definition in master branch, you can update
and use this line in initializer:

ActiveScaffold::Bridges::ActiveStorage.thumbnail_variant = {resize_to_limit:
[nil, 350]}

Regards,
Sergio

El jueves, 13 de enero de 2022 21:16:28 (CET) Gloufy escribió:
> i'v got a error config/initializers/active_scaffold.rb:3:in `<main>':
> *uninitialized constant
> ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers
> (**NameError**)*
>
> *Did you mean? ActiveStorageVariant*
> >>> <https://stackoverflow.com/questions/15680484/how-to-persist-file-upload
> >>> -fields-after-a-rails-validation-error> with activestorage and
> >>> <https://stackoverflow.com/questions/15680484/how-to-persist-file-upload
> >>> -fields-after-a-rails-validation-error> with activestorage and
> >>> activescaffold ?
> >>> https://stackoverflow.com/questions/15680484/how-to-persist-file-upload-> >>> fields-after-a-rails-validation-error
> >>>
> >>>
> >>> Thank you for your help
> >>>
> >>>
> >>> Gloufy
> >>>
> >>>
> >>> To unsubscribe from this group and stop receiving emails from it, send
> >>> an email to activescaffol...@googlegroups.com.
> >>>
> >>>
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/activescaffold/3bf5a081-ede1-4402-bf52
> >>> -1f518063b4af%40googlegroups.com
> >>> <https://groups.google.com/d/msgid/activescaffold/3bf5a081-ede1-4402-bf
> >>> 52-1f518063b4af%40googlegroups.com?utm_medium=email&utm_source=footer> .
> >>>
> >>>
> >>> To unsubscribe from this group and stop receiving emails from it, send
> >>> an email to activescaffol...@googlegroups.com.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/activescaffold/cc2b370b-1a3a-4ae1-91bf
> >>> -ff91e0ae92a2%40googlegroups.com
> >>> <https://groups.google.com/d/msgid/activescaffold/cc2b370b-1a3a-4ae1-91
> >>> bf-ff91e0ae92a2%40googlegroups.com?utm_medium=email&utm_source=footer> .
> >>
> >> You received this message because you are subscribed to the Google Groups
> >> "ActiveScaffold : Ruby on Rails Gem" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to activescaffol...@googlegroups.com.
> >
> > To view this discussion on the web visit
> >
> >> https://groups.google.com/d/msgid/activescaffold/83f86fd3-1b36-4d40-a504-> >> cc5022698e1dn%40googlegroups.com
> >> <https://groups.google.com/d/msgid/activescaffold/83f86fd3-1b36-4d40-a50
> >> 4-cc5022698e1dn%40googlegroups.com?utm_medium=email&utm_source=footer> .




Gloufy

unread,
Feb 16, 2022, 2:01:28 PM2/16/22
to ActiveScaffold : Ruby on Rails Gem
thank you so much for that !!

Do you know how to rotate image from the exif, because sometime the image is not in the right orientation :(

Thank you so much for all

ahhh do you know if active scaffold is working with rails 7.0 ?

Sergio Cambra

unread,
Feb 17, 2022, 3:44:33 AM2/17/22
to ActiveScaffold : Ruby on Rails Gem, Gloufy

Hi


Nice it's working. I found how to rotate image with imagemagick, I don't know if it's something you can use:

https://stackoverflow.com/questions/19456036/detect-exif-orientation-and-rotate-image-using-imagemagick


I don't think ActiveScaffold works with rails 7.0 yet, I haven't tested, but every version usually has some issues.


Regards

Reply all
Reply to author
Forward
0 new messages