Search code examples
ruby-on-railsruby-on-rails-3.1formtastic

Different formtastic behavior on two seemingly-identical servers


I have my app running on production and staging servers.

The identical version of code is running on both, the servers are identical in terms of versions of rails (3.1.3), gems, database schema... I'm at a loss to find any difference.

However, I have a form rendered with formtastic (2.0.0.rc5) which does not render the same on the 2 servers. In production Formtastic seems to not be correctly taking into account that the view is in the admin module.

The partial in question is at app/views/admin/composers/_form.html.erb and the relevant portion of it is:

<%= semantic_form_for @composer, :url => @composer.new_record? ? admin_composers_path : admin_composer_path(@composer) do |form| %>
    <%= form.inputs do %>
        <%= form.input :name %>

...etc...

On my staging server the form renders as expected as (note the id and name of the input field):

<form accept-charset="UTF-8" action="/admin/composers" class="formtastic admin_composer" id="new_admin_composer" method="post" novalidate="novalidate">
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="&#x2713;" />
    <input name="authenticity_token" type="hidden" value="rotbxUCJeZJuAY6eMRKaQKYdiPN0tlfQSKIeCj6VBUE=" />
  </div>
  <fieldset class="inputs">
    <ol>
      <li class="string input required stringish" id="admin_composer_name_input">
        <label class=" label" for="admin_composer_name">Name<abbr title="required">*</abbr></label>
        <input id="admin_composer_name" maxlength="255" name="admin_composer[name]" type="text" />

...etc...

on the production server, however (note the incorrect id and name):

<form accept-charset="UTF-8" action="/admin/composers" class="formtastic composer" id="new_composer" method="post" novalidate="novalidate">
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="&#x2713;" />
    <input name="authenticity_token" type="hidden" value="qt++LTRdS+V28dvTRHA7h0vGhSKSoINP8cTjLRCk088=" />
  </div>
  <fieldset class="inputs"><ol>
    <li class="string input required stringish" id="composer_name_input">
      <label class=" label" for="composer_name">Name<abbr title="required">*</abbr></label>
      <input id="composer_name" maxlength="255" name="composer[name]" type="text" />

...etc...

I've been worried that maybe there was something cached somewhere, but as far as I can tell I've forced everything to redeploy in production.

Thoughts?


Solution

  • Well, it turned out to be what I thought it might be, but I still don't quite understand why it was working in one environment and not the other.

    My new method in the controllers/admin/composers_controller.rb controller originally looked like:

    def new
      @composer = Composer.new
    end
    

    (essentially) But since I was going the route of putting everything in an admin module, what in fact needed to be was:

    def new
      @composer = Admin::Composer.new
    end
    

    (I'm using the easy trick of class Admin::Composer < Composer instead of trying to get a namespaced controller to refer to the non-namespaced model.)