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

Strange behavior with code blocks using form helpers and Slim #241

Open
javierav opened this issue Mar 3, 2020 · 3 comments
Open

Strange behavior with code blocks using form helpers and Slim #241

javierav opened this issue Mar 3, 2020 · 3 comments

Comments

@javierav
Copy link

@javierav javierav commented Mar 3, 2020

Hi!

I'm playing with this project for use in production but I encountered a possible bug related with passing a Slim/HTML block to Rails helper.

# app/components/test_component.rb

class TestComponent < ActionView::Component::Base
  def initialize(form:)
    @form = form
  end

  attr_reader :form
end
/ app/components/test_component.html.slim

div
  = form.text_field :name
  = form.label :name do
    div.label__text
      | Nombre
/ app/views/tests/show.html.slim

= form_with model: @test do |form|
  /! Test Component Start
  = render TestComponent.new(form: form)
  /! Test Component End

Expected output:

<!-- Test Component Start -->
<div>
  <input type="text" name="test[name]" id="test_name">
  <label for="test_name">
    <div class="label__text">Nombre</div>
  </label>
</div>
<!-- Test Component End -->

Current output:

<!-- Test Component Start -->
<div>
  <input type="text" name="test[name]" id="test_name">
  <div class="label__text">Nombre</div>
  <label for="test_name">
    <div>
      <input type="text" name="test[name]" id="test_name">
      <div class="label__text">Nombre</div>
    </div><!-- Test Component End -->
  </label>
</div>

In normal Rails the block of code passed to the helper works perfectly. Any ideas? Thanks!

@BlakeWilliams
Copy link
Member

@BlakeWilliams BlakeWilliams commented Mar 3, 2020

This looks really similar to the issue I ran into that caused me to open #240.

@stale
Copy link

@stale stale bot commented Aug 29, 2020

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.

@stale stale bot added the stale label Aug 29, 2020
@stale stale bot closed this Sep 5, 2020
@sanchez2210
Copy link

@sanchez2210 sanchez2210 commented Oct 9, 2020

Just ran into this and for a simple case temporarily solved it by doing

<%# 
  <% label_contents = '
    <span class="form-file-text">Cambiar imagen</span>
    <span class="form-file-button">Abrir</span>
  ' %>

  <%= @form.label(@attached_method, raw(label_contents), class: "form-file-label") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants