One solution I can think of is to put the DOM ID into an appropriate
model. In this case, I''d make RentalMap#map_filter_form_dom_id return
"map-filter-form".
However, if I do that, the contents of submit_map_filter_form.js would
need to be placed elsewhere, because RentalMap#map_filter_form_dom_id
can''t be called from the Javascript file.
I could do something like this:
Add a class method to the RentalMap model for the DOM ID:
  # rental_map.rb
  class RentalMap
    MAP_FILTER_FORM_DOM_ID = ''map-filter-form''
    def self.map_filter_form_dom_id
      MAP_FILTER_FORM_DOM_ID
    end
  end
The form in /neighbourhoods/1/map/ calls the new method:
  # map.html.erb
  <% form_remote_tag ... :html => {:id =>
RentalMap.map_filter_form_dom_id} do %>
Move the Javascript into a partial so that the new method can be
called:
  # _submit_map_filter_form.html.erb
  <script type=''text/javascript''>
    Event.observe(window, ''load'', function() {
      $(''<%=h RentalMap.map_filter_form_dom_id
-%>'').onsubmit();
      });
  </script>
The partial above must be rendered:
  # map.html.erb
  <%= render :partial => ''submit_map_filter_form'' %>
But that doesn''t feel right, for several reasons:
1) Now there''s a partial whose sole purpose is to spit out some
Javascript code (as opposed to HTML code).
2) The form''s DOM ID doesn''t feel like it belongs in a model
in the
first place.
3) As the number of DOM IDs that shouldn''t be hard-coded increases,
the models get filled up with these tiny methods.
I''d love to hear any comments and suggestions you guys have. Thanks!
Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---