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

Rails 5 compatibility #43

Closed
jasonnoble opened this issue Jul 21, 2016 · 2 comments · Fixed by #46
Closed

Rails 5 compatibility #43

jasonnoble opened this issue Jul 21, 2016 · 2 comments · Fixed by #46

Comments

@jasonnoble
Copy link

Brand new rails 5.0.0 app, add the following to Gemfile:

gem 'bootstrap-generators'

Bundle, and rails generate bootstrap:install -f.

Generate a scaffold: rails g scaffold car make:string model:string year:integer price:decimal

Start up rails server, visit http://localhost:3000/cars.

Error:

ActionView::Template::Error (The `content_tag_for` method has been removed from Rails. To continue using it, add the `record_tag_helper` gem to your Gemfile:
  gem 'record_tag_helper', '~> 1.0'

Adding the record_tag_helper line fixes the issue.

Maybe bootstrap-generators should add a runtime_dependency on record_tag_helper?

@hamadata
Copy link

Hi,

Your guess is correct.
content_tag_for is removed in Rails5, so we need to add gem 'record_tag_helper' to use it.

discussion: rails/rails#18337
tutorial: https://rubyplus.com/articles/3411-Tag-View-Helpers-in-Rails-5

@ttilberg
Copy link
Contributor

ttilberg commented May 1, 2017

Based on this comment in the discussion mentioned above, you can get around this easily.

content_tag_for (removed) is a wrapper for content_for (still here) with some class and id attribution.

After running rails generate bootstrap:install you can edit the installed template file:

# lib/templates/erb/scaffold/index.html.erb : 22ish

    <tbody>
      <%% @<%= plural_table_name%>.each do |<%= singular_table_name %>| %>
        <%%= content_tag :tr, id: dom_id(<%= singular_table_name %>), class: dom_class(<%= singular_table_name %>) do %>
          <% attributes.each do |attribute| -%>
            <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
          <% end -%>
          <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
          <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
          <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
        <%% end %>
      <%% end %>
    </tbody>

This removes the need to require a gem just to use content_tag_for.

I've submitted a PR, but this project hasn't moved in quite some time, so I'm not sure if it will get accepted. I've also only tested against my current Rails 5.1 project. Hopefully you find this useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants