<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Derrick Amenuve</title>
    <description>The latest articles on DEV Community by Derrick Amenuve (@godsloveady).</description>
    <link>https://dev.to/godsloveady</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375077%2F414db846-ffae-4117-873c-dfef1b26dfa8.jpg</url>
      <title>DEV Community: Derrick Amenuve</title>
      <link>https://dev.to/godsloveady</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/godsloveady"/>
    <language>en</language>
    <item>
      <title>Resolving ActiveStorage URL Generation Between Rails and Avo admin gem</title>
      <dc:creator>Derrick Amenuve</dc:creator>
      <pubDate>Tue, 15 Aug 2023 19:16:49 +0000</pubDate>
      <link>https://dev.to/godsloveady/resolving-activestorage-url-generation-between-rails-and-avo-admin-gem-21ib</link>
      <guid>https://dev.to/godsloveady/resolving-activestorage-url-generation-between-rails-and-avo-admin-gem-21ib</guid>
      <description>&lt;p&gt;I've been working on my project &lt;a href="https://modatongue.com"&gt;Modatongue&lt;/a&gt; and hit a roadblock with Active Storage. Images were displaying fine in lessons or my main rails application, but not in my Avo admin! 😭&lt;/p&gt;

&lt;p&gt;TLDR;&lt;br&gt;
Just change line 3 of your &lt;strong&gt;app/views/active_storage/_blobs.html.erb&lt;/strong&gt; to use main_app.url_ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s9E7dHEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q2z1wuocdognzljfxzc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s9E7dHEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q2z1wuocdognzljfxzc.png" alt="Image description" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e_rg1PZ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guewcri78y2r8lrw81c5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e_rg1PZ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guewcri78y2r8lrw81c5.png" alt="Image description" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My Battle with Active Storage (and How I Won!)&lt;/strong&gt;&lt;br&gt;
Like I mentioned earlier the Images were displaying fine in my lessons or inside the main rails app, but not in my &lt;a href="https://avohq.io/"&gt;Avo&lt;/a&gt; admin or when I logged into my admin interface! 😭&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;figure class="attachment attachment--&amp;lt;%= blob.representable? ? "preview" : "file" %&amp;gt; attachment--&amp;lt;%= blob.filename.extension %&amp;gt;"&amp;gt;
  &amp;lt;% if blob.representable? %&amp;gt;
    &amp;lt;%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %&amp;gt;
  &amp;lt;% end %&amp;gt;

  &amp;lt;figcaption class="attachment__caption"&amp;gt;
    &amp;lt;% if caption = blob.try(:caption) %&amp;gt;
      &amp;lt;%= caption %&amp;gt;
    &amp;lt;% else %&amp;gt;
      &amp;lt;span class="attachment__name"&amp;gt;&amp;lt;%= blob.filename %&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;span class="attachment__size"&amp;gt;&amp;lt;%= number_to_human_size blob.byte_size %&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;/figcaption&amp;gt;
&amp;lt;/figure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code for my blob partial(which is likely going to be your default when you install active storage). This works in Rails views, but not Avo which expects blob objects to respond to to_model. Avo admin cried undefined method 'to_model'. Ugh, why?! 🤯&lt;/p&gt;

&lt;p&gt;After a lot of trial and error, I realized Avo uses different helpers. So I tried bypassing them directly with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;%= image_tag main_app.url_for(blob) %&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;so now my blob partial will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;figure class="attachment attachment--&amp;lt;%= blob.representable? ? "preview" : "file" %&amp;gt; attachment--&amp;lt;%= blob.filename.extension %&amp;gt;"&amp;gt;
  &amp;lt;% if blob.representable? %&amp;gt;
    &amp;lt;%= image_tag main_app.url_for(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ])) %&amp;gt;
  &amp;lt;% end %&amp;gt;

  &amp;lt;figcaption class="attachment__caption"&amp;gt;
    &amp;lt;% if caption = blob.try(:caption) %&amp;gt;
      &amp;lt;%= caption %&amp;gt;
    &amp;lt;% else %&amp;gt;
      &amp;lt;span class="attachment__name"&amp;gt;&amp;lt;%= blob.filename %&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;span class="attachment__size"&amp;gt;&amp;lt;%= number_to_human_size blob.byte_size %&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;/figcaption&amp;gt;
&amp;lt;/figure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;br&gt;
The key was to bypass both helpers and generate the URL directly from Rails.&lt;/p&gt;

&lt;p&gt;This works because main_app references the root Rails application context:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;%= image_tag main_app.url_for(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ])) %&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now url_for generates the URL correctly for any ActiveStorage attachment, working identically in both Rails and Avo views.&lt;br&gt;
By leveraging the core Rails URL generation, a single rendering approach can work consistently across any frameworks layered on top of Rails. This keeps view code DRY and avoids compatibility issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eureka! It worked 🎉&lt;/strong&gt;&lt;br&gt;
Big props to the chatbots who helped clue me in - ChatGPT, Poe and especially Bard who provided the final hint. What a rollercoaster ride but so satisfying to crack it myself! 🙌&lt;/p&gt;

&lt;p&gt;I hope this helps you and feel free to say hi on &lt;a href="https://twitter.com/GodsloveADY"&gt;Twitter&lt;/a&gt;! Now back to building Modatongue.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>activestorage</category>
      <category>avo</category>
      <category>gem</category>
    </item>
    <item>
      <title>There is not only one right way</title>
      <dc:creator>Derrick Amenuve</dc:creator>
      <pubDate>Wed, 12 May 2021 09:32:32 +0000</pubDate>
      <link>https://dev.to/godsloveady/there-is-not-only-one-right-way-4dg6</link>
      <guid>https://dev.to/godsloveady/there-is-not-only-one-right-way-4dg6</guid>
      <description>&lt;p&gt;Many times when we want to work on design projects we normally think of following the best practices UX design process. This is a worrying subject for almost every designer especially beginners, we tend to ask ourselves if the flow or pattern we use is the best practice when it comes to UX design. &lt;/p&gt;

&lt;p&gt;I have come to understand that there isn't a one-way process when it comes to designing websites, web apps or mobile apps.  Your process will highly depend on the type of product you’re designing. Every project requires different approaches; the approach to designing a website for an alumni network of an institution or your alma mater differs from the way we design a cryptocurrency app(it's the new thing being talked about😀), for example.&lt;/p&gt;

&lt;p&gt;I think what we should really focus on as designers are to apply the concept of &lt;a href="https://www.interaction-design.org/literature/article/5-stages-in-the-design-thinking-process"&gt;Design Thinking&lt;/a&gt; and the principles of &lt;a href="https://www.toptal.com/designers/ui/principles-of-design"&gt;principles of design&lt;/a&gt;. The design thinking process has five stages in it: empathize, define, ideate, prototype, and test&lt;br&gt;
This should be great for any kind of project ✌🏽.&lt;/p&gt;

&lt;p&gt;My next post will be a brief on the process I used when designing a website for my Alumni network. Stay tuned, mia ga do go🤝 (meaning we will meet again, translated from Ewe- a Ghanaian language)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>design</category>
    </item>
  </channel>
</rss>
