Skip to content

Instantly share code, notes, and snippets.

@cuciferus
Created February 6, 2013 16:07
Show Gist options
  • Save cuciferus/4723596 to your computer and use it in GitHub Desktop.
Save cuciferus/4723596 to your computer and use it in GitHub Desktop.
coffee:
$modal = $('#modal')
$modal_close = $modal.find('.close')
$modal_container = $('#modal-container')
#pt toate linkurile cu data-remote!
$(document).on 'ajax:success', 'a[data-remote]',(xhr, data, status) ->
$modal
.html(data.html)
.prepend(modal, close)
.css('top',$(window).scrollTop()+40)
.show()
$modal_container.show()
$(document).on 'click', '#modal .close', ->
$modal_container.hide()
$modal.hide()
false
new.js.erb:
$('#dialog-form').html('<%= escape_javascript(render('form-modal')) %>');
partial _form_modal.html.erb:
<div id = "modal-container"></div>
<div id = "modal">
<h2> salut</h2>
<a href="#" class="close">Inchide</a>
</div>
controller
def new
@pacient = Pacient.includes(:evaluares => [:paraclinics]).find(params[:pacient_id])
@evaluare = Evaluare.new
respond_to do |format|
format.js { render :json =>{:html=> render_to_string('evaluares/_form-modal'), :content_type =>'text/json'}}
format.html # new.html.erb
format.json { render json: @evaluare }
end
end
@cuciferus
Copy link
Author

Started GET "/pacients/828/evaluares/new" for 192.168.2.2 at 2013-02-06 17:57:58 +0200
Processing by EvaluaresController#new as JS
Parameters: {"pacient_id"=>"828"}
Pacient Load (0.1ms) SELECT "pacients".* FROM "pacients" WHERE "pacients"."id" = ? LIMIT 1 [["id", "828"]]
Evaluare Load (0.3ms) SELECT "evaluares".* FROM "evaluares" WHERE "evaluares"."pacient_id" IN (828) ORDER BY data
Paraclinic Load (0.6ms) SELECT "paraclinics".* FROM "paraclinics" WHERE "paraclinics"."evaluare_id" IN (6665, 6896, 7297, 8134)
Rendered evaluares/_form-modal.html.erb (0.1ms)
Completed 200 OK in 11ms (Views: 0.2ms | ActiveRecord: 1.1ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment