Ahmed Nadar

Joined

740 Experience
6 Lessons Completed
0 Questions Solved

Activity

The only way I see it now is duplicate code for every element. Other solutions?

If you would apply this feature on several elements on the same page or multiple pages what is the best approach to do so?

Awsome work Chris. Thanks!

Posted in Enable turbo_frame: modal tag conditionally

I have a link for creating a new item


  • <%= link_to "List an item", new_item_path, data: { turbo_frame: 'modal' } %>
  • This opens a item form in a turbo_frame_tag modal <%= turbo_frame_tag "modal" %>

    What I need to do is, allow regular users to list 3 items only while Admin can list more items. And if they click on above link it redirect it to root_path with a flash notice.

    I have such validation in item controller:

    before_action :check_limited_items, if: :signed_in?, only: :new

    def check_limited_items
    limited_items = 3
    return unless current_user.items_count == limited_items

    redirect_to root_path
    flash[:notice] = "Allow 3 items only."
    

    end
    When I click on above link for a new item, it does nothing. When i refresh, flash notice shows up.

    How could I fix that? And is a controller a good place for validation or model? I tried both and same result.
    Also, I use Pundit for authorizations, can it help using scopes?

    Posted in Realtime Nested Comments: Part 3 Discussion

    Is it possible to render signed_in? inside partial _comment_with_replies.html.erb without errors?

    Inside the partial, I have <% if signed_in? %> to check if user signed in first to show Reply section. When i do so, it throw Devise famous error Devise could not find theWarden::Proxyinstance on your request environment..

    Any solution?

    Posted in How to use Devise with Hotwire & Turbo.js Discussion

    I had similar issue and it was puzzling me, every time I signup i got redirected to /users which it didn't had any authentication restrictions. Until i notice that I had method: :put for form_for:
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name),html: { method: :put, data: { turbo: false } }) do |f| %>

    Once I removed method: :put, everything worked nicely.

    Posted in How to use ESBuild in Rails with JSBundling Discussion

    Exactly. Working with Webpacker was painful compare to ESBuild. I'm really enjoying the workflow and process with Rails 7 new features.

    Speaking of which, wouldn't you use importmap instead of dealing with JS complexity?

    Posted in Realtime Nested Comments: Part 3 Discussion

    Thanks Chris!

    Inside _comment.html.erb I'm calling @item.user as bellow:

    <div class="flex flex-col w-full text-gray-700 <%='bg-gray-200 m-1 p-1 rounded-md' if comment.user === @item.user%>">
    
        <div class="relative flex flex-wrap items-center mb-1">
            <% if comment.user.avatar.attached? %>
    
            <div class="relative flex flex-col items-center group">
                <%= link_to comment.user do %>
                <%= image_tag url_for(user_avatar(comment.user, 300)), class: "rounded-full h-12 w-12 align-middle border-none shadow-lg mr-2", alt: comment.user.name, label: comment.user.name %>
                <%end%>
                <div class="absolute bottom-0 flex flex-col items-center hidden mb-12 right-1 -left-1 group-hover:flex">
                    <span class="relative z-10 p-2 text-xs font-semibold leading-none leading-relaxed text-white whitespace-no-wrap bg-black rounded-md shadow-lg min-w-max"><%= comment.user.name%></span>
                    <div class="w-3 h-3 -mt-2 rotate-45 bg-black"></div>
                </div>
            </div>
          </div>
       </div>
    

    And I get an error undefined methoduser' for nil:NilClassfrom@item.user.
    How could I get
    @item` variable works inside comment?
    Any better approach?
    Thanks!

    Posted in How to use Hotwire in Rails Discussion

    Hotwire is amazing. I tired different mini-apps to using Hotwire feature. While I know I can edit a form, could i edit an attribute (such as an email) on its own without editing/submitting the whole form?

    Posted in Looking for Rails work? / Hiring Rails developers?

    I'm a web dsigner and developer. With years of experince in Front-End, Design and Rails.
    Looking for a remote job, work with startups and bsuiness owners.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.