Monogot
Monogot

Reputation: 191

RoR link_to action in div and pass params

I have link_to and when i click link then div(id="edit_comment_form") showed (This div is form for user edit content) and i want pass params[:cc] from link_to to div This is source code.

<%= link_to "Edit", "#edit_comment_form", :class => "btn", "data-toggle" => "modal" %>

<div id="edit_comment_form" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

<%= form_tag({controller: "comments", action: "edit"}, method: "get", class: "xxx") do %>
<div class="modal-body">

  <%= text_area_tag :comment, "" ,rows: 10,:style => "width:515px; resize: none;",:placeholder => "Please type your comment." %>

  <%= hidden_field_tag(:cc, params[:cc]) %> ### I want params[:cc]

</div>

<div class="modal-footer">
  <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  <%= submit_tag "Vote",:class => "btn btn-primary" %>
</div>

<% end %>

How can i pass params to div. Please help me!

Upvotes: 0

Views: 386

Answers (1)

Bryan Corey
Bryan Corey

Reputation: 760

You will need to use "data-cc" if you want it to be an HTML attribute on the <a> element and not break the validity of your HTML. You will need to write a custom javascript onclick handler if you want to pass data into the form on click, regardless of how you structure the data into the <a> element that link_to creates.

This post states you shouldn't use data-toggle when you want additional functionality, to prevent some other issues that will arise. You will likely need to build out a full onclick event handler yourself.

Upvotes: 0

Related Questions