Activity
I have a model that has a photo attached and this photo has few variants.
I would like to display many of these photos as a gallery and i am using one of the variants as a thumbnail and another one as a light box representation. Pretty straightforward.
I noticed that this variants are generated on first request, which can take quite some time for the first user as there can be many photos in a single gallery.
Is there a way to generate variants after the model has been successfully saved?
Preferably in background.
I was searching around and could't find any resources on this, but maybe i was not persistent enough :)
Anyway, I would appreciate any tips on this.
Reply 2 :) - i've been able to make it work with button_to which wraps it in the form, and then in stimulus controller i prevent default, find closest "form" and after swal is confirmed send request with form.submit. That's the only way i see how. As soon as i fiddle around with turbo etc, it's chaos. But it works and it's fine.
Hi everyone. I would like to have SWAL2 triggered instead of normal JS confirm popup and I have managed to do that with a link_to and stimulus controller + Request.js - but only if i return turbo_stream with destroy.turbo_stream.erb and remove/replace something on the same page.
Now i am struggling in achieving basically exactly the same thing - but redirecting to a different page.
I am comparing logs of normal delete as Chris has shown in the video and my approach and there is no differences at all. But In my case, with SWAL, nothing changes on the page and it basically renders to i don't know what. Page just stays the same and although in the log i can clearly see redirect and 303 and get, it doesn't do that. I don't even have turbo_stream respond (just like Chris doesn't) and there is absolutely no turbo-frames in the page. But to me it seems it's like it just logs 303, but in reality just tries to render to the same page and as there is no turbo-frame it basically renders to /dev/null :)
Can somebody maybe explain how i could have delete, SWAL and redirects?
Maybe i am over complicating with Request.js, but i don't know how to do it differently.
Thank you
Reply to myself: i figured out i am doing remote request, so it is normal that it does not work :), stupid me. But i would still like to know how to do it properly with SWAL. It's a tough one for me.
This approach is very interesting and I would like to understand and use it in a larger scale.
Also, eagerly waiting for the Rolify video as promised :)
So, the thing I don't fully understand here is, how to approach it when I need to add dynamic permissions for other models, too. Let's say PostCategory as video talks about Posts (and there will naturally be many many more).
How would I then scale configuration on the roles?
Adding flat attributes, where in this case i would say post_category_read, post_category_create in addition to the ones for Post, or maybe a nested JSON, where i would have post: { read, create, etc. }, post_category : {read, create, etc...} - if nesting is even possible, not sure right now.
Or maybe creating a separate attributes on Role altogether. Like post_permissions, post_category_permissions, etc...
Maybe I got it all wrong in the first place. I am a bit scared going this way and realizing it doesn't scale in a good way. Thanks for any tips
Hey Chris. Very interesting episode and solution.
I am trying to implement something like this (because you gave me an idea), but would like to extend it much further.
I am going with Gon gem, which is basically the same you are doing, but with different approach.
What I would like to do actually is a wee bit harder than what is shown here, because a proper authorization is needed, not just role based.
I would like to do this with CanCanCan, but I don't relly know how to do it properly and maintainable.
Currently I have a user's ability permissions hash, but how to actually do it in JS - here i have problems.
Any ideas? Do you think this is too much and doesn't really weight out caching?
Caching is great to make a site much faster, but with the cost of simplicity. Everything is ballooning in complexity.
Any thoughts?
Hey Chris. Do you have any tips on expiring childrens when parent changes, where simple touching doesn't apply. Imagine a table of students and their related classes. You cache row fragments. When name of the class changes, rarely, but can, you have to expire all student fragments of the changed class.