How to call controller action on click and modal in Rails -
i'm trying figure out how manage ability phone call controller link , homecoming info after process completed, while @ same time displaying modal info returned. here's logic have yet figure out , hope can help;
i've tried next no success;
#html <%= link_to "#widgetgenmodal", :data => {:toggle => "modal"}, :action => 'gen_key', :class => 'gen-widget pull-right' %><i class="fa fa-slideshare fa-1x"></i><% end %> #controller (widget controller) protected def generate_token user = current_user self.token = loop random_token = securerandom.urlsafe_base64(nil, false) break random_token unless user.widget.exists?(token: random_token) end end #modal (bootstrap) <div class="modal fade" id="widgetgenmodal" tabindex="-1" role="dialog" aria-labelledby="widgetgenmodal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h3 class="modal-title" id="widgetgenmodal"><div class="btn btn-danger btn-xs">new</div> share category</h3> <p>we've made easier share store / save within categories. re-create specially generated code, paste on website or share link allow them see you've saved.</p> </div> <div class="modal-body"> </div> <div class="modal-footer"> <div id="test"></div> <%= f.hidden_field :color, value: '' %><div id="output"></div> <div class="clearfix visible-xs"></div> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div> <!-- /.modal -->
i guess i'm having hard time moving token
modal i'm trying work out here. suggestions?
one way render empty modal in view , give id body. after sending ajax request action render .js file injects new info body of modal , use
$("#modal_id").modal("toggle")
ex :: in view ::
<%= link_to "name of link", path_to_your_action, :"data-toggle"=>"modal", :"data-target"=>"#widgetgenmodal", class: "company-name-link", remote: true%> <%= render "your_empty_modal_partial"%>
in empty modal partial
<div class="modal fade" id="widgetgenmodal" tabindex="-1" role="dialog" aria-labelledby="widgetgenmodal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h3 class="modal-title" id="widgetgenmodal"><div class="btn btn-danger btn-xs">new</div> share category</h3> <p>we've made easier share store / save within categories. re-create specially generated code, paste on website or share link allow them see you've saved.</p> </div> <div class="modal-body" id="widgetgenmodalbody"> </div> <div class="modal-footer"> <div id="test"></div> <%= f.hidden_field :color, value: '' %><div id="output"></div> <div class="clearfix visible-xs"></div> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div> <!-- /.modal -->
please check logic f.hidden_field not right.
in action ::
def your_action // whatever format.js end
in your_action.js file in views
$("widgetgenmodalbody").html('<%= info returned or partial containg info %>') $("widgetgenmodal").modal("toggle")
ruby-on-rails
No comments:
Post a Comment