Friday 15 February 2013

ruby on rails - Opening show view using bootstrap3 modal in rails4 -



ruby on rails - Opening show view using bootstrap3 modal in rails4 -

while sending request client giving 500 internal server error. i'm using bootstrap 3, rails 4 combined several other gems devise, mysql database.

error log:

get http://localhost:3000/admin_panel/hotels/6 500 (internal server error) jquery.js?body=1:9632 send jquery.js?body=1:9632 jquery.extend.ajax jquery.js?body=1:9177 $.rails.rails.ajax jquery_ujs.js?body=1:84 $.rails.rails.handleremote jquery_ujs.js?body=1:164 (anonymous function) jquery_ujs.js?body=1:342 jquery.event.dispatch jquery.js?body=1:4642 elemdata.handle

controller:

class hotelscontroller < applicationcontroller before_action :authenticate_admin_panel! def index @hotels = hotel.all end def show @hotels = hotel.find(params[:id]) respond_to |format| format.html format.json { render json: @hotels } end end

show.haml:

:javascript $('#mymodal').html('#{j render("show")}');

_show.haml

#mymodal %table.table.table-hover %tr %td id %td= @hotels.id %tr %td hotel name %td= @hotels.hotel_name %tr %td description %td= @hotels.description %tr %td address %td= @hotels.address %tr %td postal code %td= @hotels.postal_code %tr %td city %td= @hotels.city %tr %td state %td= @hotels.state %tr %td country %td= @hotels.country %tr %td longitude %td= @hotels.longitude %tr %td latitude %td= @hotels.latitude %tr %td rooms %td= @hotels.rooms %tr %td cost %td= @hotels.price %p= link_to 'back', hotels_path

application.js:

var clickonpopuplink = function(){ $('body').on('click', '.static-popup-link', function(){ $('#mymodal').modal('show'); }); } clickonpopuplink();

index.haml

= link_to 'view', hotel, {:remote => 'true', 'class' => 'static-popup-link'} .modal.hide.fade#mymodal{:tabindex => '-1', :role => 'dialog', :'data-backdrop' => 'static', :'data-keyboard' => 'false'} loading...

i think want dinamically add together content in modal hotels every time user click in body. 1 way using javascript response in action , not html, alter action show with:

respond_to |format| format.js end

rename show.haml show.js.haml , fill code:

:plain $('#mymodal').html('#{escape_javascript(render(partial: "show") )}');

in partial view _show.haml showing info hotels utilize @hotels.each

ruby-on-rails ruby-on-rails-4 haml

No comments:

Post a Comment