Question

I have installed Advanced Roadmap plugin on redmine project. After Installation if I try to create a new milestone, following error is thrown:

  ActionView::Template::Error (undefined method `observe_field' for # 


The form partial is as follows :

<%= error_messages_for 'milestone' %> <div class="box"> <p><%= f.text_field :name, :size => 60, :required => true %></p> <p><%= f.text_field :description, :size => 60 %></p> <p><%= f.text_field :effective_date, :size => 10 %><%= calendar_for('milestone_effective_date') %></p> <p> <select id="project_selector"> <% @projects.each do |project| %> <option<%= (project == @project) ? " selected" : "" %> id="<%= project.id %>"><%= h(project.name) %></option> <% end %> </select> <% javascript_tag :defer => "defer" do %> function project_changed() { object = window.document.getElementById("project_selector"); if (object) { if (object.selectedIndex != -1) { project_id = object.options[object.selectedIndex].id; <% @projects.each do |project| %> project_div = window.document.getElementById("project_<%= project.id %>_versions"); if (project_div) { project_div.style.display = "none"; project_div.style.visibility = "hidden"; } <% end %> project_div = window.document.getElementById("project_" + project_id + "_versions"); if (project_div) { project_div.style.display = ""; project_div.style.visibility = ""; } } } } jQuery(function($) { $(\"#project_selector\").change(project_change); }) <% end %> </p> <% @projects.each do |project| %> <div id="project_<%= project.id %>_versions"<%= (@project == project) ? "" : "style=\"display: none; visibility: hidden;\"" %>> <table class="list"> <thead> <th><%= l(:field_version) %></th> <th><%= l(:field_effective_date) %></th> <th><%= l(:field_description) %></th> <th><%= l(:label_milestone_plural) %></th> </thead> <% project.versions.sort.each do |version| %> <tr class="<%= cycle("odd", "even") %>"> <td> <%= check_box_tag "versions[]", version.id, @milestone.versions?(version) %> <%= link_to(h(version.name), :controller => :versions, :action => :show, :id => version) %> </td> <td align="center"><%= version.effective_date %></td> <td><%= version.description %></td> <td align="center"><%= version.milestones.collect {|m| link_to(h(m.name), :controller => :milestones, :action => :show, :id => m.id) }.join(", ").html_safe %></td> <tr> <% end %> </table> </div> <% end %> </div>

How should we change he observe field issue as it has been deprecated.Any help will be appreciated.

I am using

  • ruby 1.9.3 -version
  • rails 3.2.13 version
  • redmine 2.x
Was it helpful?

Solution

After a little search i found the solution for the above issue.

Obviously observe_field method has been deprecated in rails 3.
So in order to solve this issue, we need to just remove the observe_field helper method and add a javascript code inside javascript_tag of the view template as follows:

<% javascript_tag :defer => "defer" do %>
  function project_changed()
  {
    object = window.document.getElementById("project_selector");
    if (object)
    {
      if (object.selectedIndex != -1)
      {
        project_id = object.options[object.selectedIndex].id;
        <% @projects.each do |project| %>
          project_div = window.document.getElementById("project_<%= project.id %>_versions");
          if (project_div)
          {
            project_div.style.display = "none";
            project_div.style.visibility = "hidden";
          }
        <% end %>
        project_div = window.document.getElementById("project_" + project_id + "_versions");
        if (project_div)
        {
          project_div.style.display = "";
          project_div.style.visibility = "";
        }
      }
    }
  }
  jQuery(function($)
  {
    $(\"#project_selector\").change(project_change);
  })
<% end %>

what exactly is done is just we removed helper method and added a small jquery code.

  jQuery(function($)
  {
    $(\"#project_selector\").change(project_change);
  })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top