1

I have the following code in the controller. I am populating a drop down box dynamically based on the selection from another drop down box.

def  update_releases 
  project = Project.find(params[:project_id]) 
  releases = project.releases
  puts "releases==#{releases}" 
  render :update do |page| 
  page.replace_html 'releases', :partial => 'releases', :object => releases 
end 

view code:

-form_tag reports_path(report_type=1),:method => :get, :multipart => true ,:id => "filter" do  
%table.grid.full
%tr      
  %td.grid.full_panels{:style => "width: 20%"}
    Project:
  %td.grid.full_panels{:style => "width: 20%"}
    //= select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]),{:onchange => "#{remote_function(:url  => {:action => "update_releases"},:with => "'project_id='+value")}"} 
    = select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]), :class => "update_releases"


  %td.grid.full_panels{:style => "width: 20%"}
    Releases:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="releases">
    = render :partial => 'releases', :object => @releases
  %td.grid.full_panels{:style => "width: 20%"}
    Cycles:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="cycles">
    = render :partial => 'cycles', :object => @cycles

%tr      
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
    =submit_tag "Submit"

= javascript_include_tag "pages/ic"

partials code : = select_tag "releases",options_from_collection_for_select(releases,"id","name",params[:releases])

Jquery: //change the releases drop down based on the selction of the projects drop down.

$('.update_releases').live("change", function(){
  $.ajaxSetup({beforeSend: function(xhr) {xhr.setRequestHeader("X-CSRF-Token", $("meta[name='csrf-token']").attr("content")); }});
  var project_id=($(this).val());
  $.post('/reports/update_releases', {project_id: project_id});
 return false;
})

I am getting an error element doesn't support this property" as a pop up on chaning the selection in the drop down box. Please help me out here.

Mark Huk
  • 2,379
  • 21
  • 28
ramya
  • 928
  • 5
  • 14
  • 30
  • 1. Where `cycles` is defined? 2. Add some View code to see full picture.. – Mark Huk Oct 19 '11 at 07:02
  • Hi Mark I have added the full code. Also please let me know if some changes are to be done in jquery for including page.replace_html. – ramya Oct 19 '11 at 07:21
  • Use `#releases` instead of `
    `. : Looks like your HAML is invalid. Check the HTML output on the Client-side is there releases and cycles divs are present.
    – Mark Huk Oct 21 '11 at 08:31
  • Releases and cycles are present. Replace_html uses prototype. Can anyone let me know the corresponding jquery method for that – ramya Oct 21 '11 at 09:24
  • `replace_html` is RJS method. It compiles Your ruby into JS. If you set up the prototype as RJS backend, then Prototype methods will be used and the same for jQuery. As for the replacing of the html: see method `html()` on [http://api.jquery.com/html/] (http://api.jquery.com/html/) – Mark Huk Oct 21 '11 at 09:59

1 Answers1

1

As simple workaround try to use this code in controller:

respond_to do |format| 
  format.js render :partial => 'releases', :locals { :releases => releases }
end

In releases.js.haml:

   $('#releases').html('#{render :partial => '<some_old_html_partial>', :locals => {:releases => releases}}')
Mark Huk
  • 2,379
  • 21
  • 28
  • Hi in the place of what should be given. – ramya Nov 01 '11 at 11:04
  • Hi, in place of should be the template name to render, that should replace the existing HTML on client. For example, 'releases' (As in your post). Be aware to use correct names, as there would be releases.**js**.haml and releases.**html**.haml and you will be resposive for telling Rails which template to render (Either by telling to render :file => '' or by another way). – Mark Huk Nov 01 '11 at 12:29