0

This is a simple question but I can't seem to find a solid answer. I simply want to know if this is valid? it's a basic form_for with in input at the bottom.

## Form

 <%= form_for @snitch, html: { class: "form-actions", method: 'delete' } do |form| %>
 <span class="button-text"><%= link_to 'NO WAY!', home_base_url_or_default(root_path), rel: "modal:close" %></span>
 <button type="submit" class="button button--modal delete-snitch" data-snitch-id="<% @snitch.token %>" value="Yes, delete it.">
 <% end %>

Is the third line valid? specifically where it says data-snitch-id="<% @snitch.token %>"? if it is not. can someone help me figure out how I can do something like that?

0

2 Answers 2

2

HTML data attributes are perfectly valid and widely supported. They're used to store custom data in an element. You can create elements with those attributes in rails helpers as well.

<%= button_tag "Yes, delete it.", type: :submit,
    data: {"snitch-id" => @snitch.token}, 
    class: 'button button--modal delete-snitch' %>

The only problem with your example is that you're not printing the value of @snitch.token. You should be using <%= @snitch.token %> instead of <% @snitch.token %>

Sign up to request clarification or add additional context in comments.

Comments

0

Use #{ } expression instead.

data-snitch-id="#{@snitch.token}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.