Monday, 15 February 2010

ruby on rails - Using a helper method to insert html into document -



ruby on rails - Using a helper method to insert html into document -

using twitter bootstrap our rails 4 app, want create helper function add together link page that, when clicked, produced modal popup renders show template. think i'm close though, when page function called loads, button displayed, when clicked, produces modal raw ruby injection, this:

class="lang-rb prettyprint-override"><%= render :template => 'imprintables/show', locals: { modal: true, id: 1 } %>

my problem instead of displaying injection, i'd ruby injection preformed. general style advice , other pointers/criticism appreciated. give thanks you!

application_helper.rb:

module applicationhelper def imprintable_modal(imprintable) raw %( <div class="col-lg-3 text-right"> <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#basicmodal">click imprintable info</a> </div> <div class="modal fade" id="basicmodal" tabindex="-1" role="dialog" aria-labelledby="basicmodal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body"> <%= render :template => 'imprintables/show', locals: { modal: true, id: #{imprintable.id} } %> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div> </div> </div> </div> ) end end

if understood correctly, , content of template 'imprintables/show' need not loaded dynamically (through ajax), suggest utilize plain old templates.

app/views/application/_modal.html.erb:

<div class="col-lg-3 text-right"> <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#basicmodal">click imprintable info</a> </div> <div class="modal fade" id="basicmodal" tabindex="-1" role="dialog" aria-labelledby="basicmodal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body"> <%= render :template => 'imprintables/show', locals: { modal: true, id: #{imprintable.id} } %> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> </div> </div> </div> </div>

and in application_helper.rb:

module applicationhelper def imprintable_modal(imprintable) render :partial => 'modal', :locals => { :imprintable => imprintable } end end

ruby-on-rails ruby twitter-bootstrap modal-dialog

No comments:

Post a Comment