Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active storage attachments cant render #628

Open
reeganviljoen opened this issue Jun 21, 2024 · 1 comment
Open

Active storage attachments cant render #628

reeganviljoen opened this issue Jun 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@reeganviljoen
Copy link

reeganviljoen commented Jun 21, 2024

Describe the bug

Using active storage attachments inside a component rendered inside lookbook fails due to lookbook being its own isolated engine so a component(or partial) with url_for(user.avatar) will not be able to render the attachment used in lookbook but not normally

To Reproduce

Steps to reproduce the behavior:

  1. Create a component with an attachemnt, i.e:
class AvatarComponent < ViewComponent::Base

    def initilize(user)
    @user = user
  end

  def avatar
    url_for(@user.avatar)
  end
end

= image_tag avatar, class: 'c-avatar'

  1. Create a preview, i.e:
class Components::AvatarComponentPreview < ApplicationPreview

  def default(user: User.last)
    render(AvatarComponent.new(user: user))
  end
end

  1. See error
    image
    then when i open the image up(i.e http://localhost:3000/lookbook/rails/active_storage/blobs/redirect/<secure_id>/my_image.jpeg)
    image

Expected behavior

Lookbook should be able to render the attachment in the component like the default rails engine is able too

Version numbers

Please complete the following information:

  • Lookbook: 2.2.0
  • ViewComponent: 2.83.0
  • Rails: 7.1.3.2
  • Ruby: 3.3.0
@reeganviljoen reeganviljoen added the bug Something isn't working label Jun 21, 2024
@allmarkedup
Copy link
Collaborator

@reeganviljoen Thanks for the detailed bug report and many apologies for taking so long to get back to you on this.

I've just tried to reproduce the issue in one of my apps that is using ActiveStorage and I've so far not been able to replicate the issue - but I suspect that is because of a different controller/preview class setup somehow.

I've got a few questions that would help me figure out what is going on here, if you are still interested in this issue despite me taking so long to reply!

  1. Are you using a custom preview controller class? If so could you share what this looks like?
  2. The ApplicationPreview class that your preview class inherits from - is that just example pseudo-code or are you using a custom Preview class? What does that inherit from if so?

One thing you could also try (although I'm not sure it would make any difference in this situation) is to try calling the host application's url_for method within your component like so:

helpers.main_app.url_for(@user.avatar)

I realise that is not ideal but it would be interesting to know if that results in the correct URL being rendered or not.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants