ViewComponent / view_component

A framework for building reusable, testable & encapsulated view components in Ruby on Rails.
https://viewcomponent.org
MIT License
3.29k stars 430 forks source link

Haml error: ActionView::Template::Error (undefined method `capture_haml' ...) #426

Closed spdawson closed 4 years ago

spdawson commented 4 years ago

Steps to reproduce

Minimal reproduction repository

Expected behavior

Component should render without incident, when using Haml template.

Actual behavior

Error is raised:

ActionView::Template::Error (undefined method `capture_haml' for #<#<Class:0x00007fc4fcb73338>:0x00007fc4fcaca440>
Did you mean?  capture_with_haml):

System configuration

Rails version: 6.0.3.2

Ruby version: 2.7.1

Gem version: 2.18.0

joelhawksley commented 4 years ago

@spdawson thank you for the report! We definitely want to make sure haml works with ViewComponent. Would you be willing to write a PR with a test case for this issue?

spdawson commented 4 years ago

@joelhawksley I've added a test case in #428

joelhawksley commented 4 years ago

Thanks @spdawson! Would you be up for pairing with me on this one? Send me an email: joelhawksley@github.com

dmarcoux commented 4 years ago

I would be willing to help if it's needed. I plan to use view components with Haml at work. If Haml doesn't work with view components right now, it's a blocker. Let me know how I can help.

joelhawksley commented 4 years ago

@dmarcoux send me your pairing availability for the next week to joelhawksley@github.com ❤️

dmarcoux commented 4 years ago

@dmarcoux send me your pairing availability for the next week to joelhawksley@github.com heart

Done :slightly_smiling_face:

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

manuelpuyol commented 4 years ago

hey @spdawson @dmarcoux I was taking a look at this issue and the repository provided, I noticed it is using helpers.link_to. As https://github.com/github/view_component/pull/428#discussion_r468713628 explained, helpers. is unnecessary in this situation and removing it solved the issue (at least in the provided repo)

Could you confirm that removing helpers. fixes the issue? Also, is there any specific reason as why you are using helpers.?

spdawson commented 4 years ago

Could you confirm that removing helpers. fixes the issue? Also, is there any specific reason as why you are using helpers.?

Yes, removing the helpers. scope does resolve this issue for me; thanks @dmarcoux!

morgler commented 2 years ago

I do get this error even without any helpers in my templates. My component however renders a rails form and another component within it.

default.html.erb (preview template):

<%= form_with model: @gig do |f| %>
  <%= render Places::EditComponent.new(form: f, attr_name: :venue) %>
<% end %>

edit_component.html.haml (the component itself):

= @form.fields_for @attr_name do |pf|
  %div{class: errors.present? ? 'has-error' : ''}
    = render Places::MapComponent.new(place: place, style: @style, fireEvent: @fireEvent)

The error message points to the @form.fields_for line.

Btw: If I write the default.html.erb template in haml (instead of straight erb), I get the following error:

A preview template for example default does not exist.
To fix this issue, create a template for the example.

Is there anything special to set up in order to use templates for previewing view components?