I am trying to load dynamic content onto a view page by rendering a partial. I followed the procedure suggested in this link. I have a view page receive_names.haml It has a form and div to add dynamic content.
My receive_names.haml
%form{"accept-charset" => "UTF-8", :action => "/names/updatepage", :method => "post", :remote => "true"}
#form inputs linke texbox
%button#submitbutton.btn.btn-lg.btn-primary{:type => "submit"} Search
.container
#dynamicLoadingPanel
Once this form is submitted my controller action is invoked.
My controller code names.rb
class NamesController < ApplicationController
def receive_names
puts "--------Inside get receive_names--------------"
#to show the initial receive_names.haml
end
def updatepage
puts "----------------------inside updatepage action------------------"
respond_to do |format|
format.js
end
end
end
My updatepage.js in assets/jasvacripts
window.alert("Error");
$("#dynamicLoadingPanel").html('<%=escape_javascript(render :partial=>"sample_table")%>');
My sample_table partial with name _sample_table.haml
%table{:style => "width:100%"}
%tr
%td Jill
%td Smith
%td 50
%tr
%td Eve
%td Jackson
%td 94
%tr
%td John
%td Doe
%td 80
My application.haml from view/layouts.
%html
%head
%title Title
= stylesheet_link_tag 'application', :media => 'all'
= javascript_include_tag 'application'
%body
%br
%h2{:align => "center"} Title
= yield
My expection is that on click on submit button from receive_names.haml the controller action updatepage will be invoked and from the controller action updatepage.js will be invoked and that will add dynamically to the partial(sample_table) to the div on the receive_names.haml and the page receive_names.haml will be displayed with the dynamicaaly added table.
But what is happening is when i try to load the receive_names.haml intially(before filling the form and submitting) the application.haml is executing the js file and i could see the alert message. shouldnt the js be executed only from the controller action updatepage ?? And if i go ahead and submit the form anyhow i am getting directed to a empty page with url names/updatepage (default view).
Can any one tell me whats going wrong here ??
Aucun commentaire:
Enregistrer un commentaire