Rails - Controller variables are nil in the views on Production only. Works fine locally
<p>Trying to navigate to <code>domain.com/company_entites/new</code>. And it hits the <code>new</code> action and renders the <code>new</code> form as per our <code>new.html.erb</code> view. This works fine locally. </p>

<p>But on the server - the same sequence errors out! </p>

<p>Through debugging we see that - for <code>CompanyEntitiesController</code> - none of the actions pass the data set to the @variables. But unable to figure why?</p>

<p>We changed the name of the variables. We set variables with constants (and not from DB) but the variables show up <code>nil</code> in the views. Note - This happens ONLY in the production server but the same code works fine locally!</p>

<p>CompanyEntitesController.rb</p>

<pre><code>class CompanyEntitiesController &lt; ApplicationController
  before_filter :authenticate_user!
  before_action :set_company_entity, only: [:show, :edit, :update, :destroy]

  respond_to :html

  def new
   @company_entity = CompanyEntity.new
   respond_with(@company_entity)
  end
end
</code></pre>

<p>Error</p>

<pre><code>Started GET "/company_entities/new" for 1.1.1.1 at 2016-03-04 09:39:57 -0500 I, 

[2016-03-04T09:39:57.737434 #7243]  INFO -- : Processing by CompanyEntitiesController#new as HTML I,

[2016-03-04T09:39:57.826523 #7243]  INFO -- :   Rendered company_entities/_form.html.erb (5.7ms) I,

[2016-03-04T09:39:57.826932 #7243]  INFO -- :   Rendered company_entities/new.html.erb within layouts/admin_lte_2 (11.6ms) E,

[2016-03-04T09:39:57.827367 #7243] ERROR -- : Caught exception : ArgumentError : First argument in form cannot contain nil or be empty E,


[2016-03-04T09:39:57.827485 #7243] ERROR -- : /home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/helpers/form_helper.rb:423:in `form_for'
/home/bobdiya/apps/2dotO_staging/releases/20160304142845/app/views/company_entities/_form.html.erb:3:in `_app_views_company_entities__form_html_erb__3158067205622819281_41143500'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/template.rb:145:in `block in render'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.12/lib/active_support/notifications.rb:161:in `instrument'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/template.rb:339:in `instrument'
I, 

[2016-03-04T09:39:57.829225 #7243]  INFO -- :   Rendered text template (0.1ms)
I, 
[2016-03-04T09:39:57.829886 #7243]  INFO -- : Completed 500 Internal Server Error in 92ms (Views: 1.4ms)
</code></pre>

<p><strong>Edit</strong></p>

<ul>
<li>Debugging as suggestion by @brahmana</li>
</ul>

<p><strong>new</strong></p>

<pre><code> def new
    @company_entity = CompanyEntity.new
    Rails.logger.debug @company_entity.inspect+"debugging company----------------------------------------"
 end
</code></pre>

<p><code>/app/views/company_entities/new.html.erb</code></p>

<pre><code>&lt;section class="content"&gt;
&lt;div class="box box-primary"&gt;
 &lt;div class="box-header"&gt;
   &lt;h3 class="box-title"&gt;New Company Entity&lt;/h3&gt;
 &lt;/div&gt;&lt;!-- /.box-header --&gt;

&lt;%= render 'form' %&gt;
</code></pre>

<p><code>/app/views/company_entities/_form.html.erb</code></p>

<pre><code>   &lt;div class="box-body"&gt;
  &lt;%= debug @company_entity %&gt;
 &lt;%= debug "debugging in view ========================== "%&gt;
  &lt;%= form_for(@company_entity) do |f| %&gt;
   &lt;% if @company_entity.errors.any? %&gt;
     &lt;div id="error_explanation"&gt;
       &lt;h2&gt;&lt;%= pluralize(@company_entity.errors.count, "error") %&gt; prohibited this company_entity from being saved:&lt;/h2&gt;

      &lt;ul&gt;
      &lt;% @company_entity.errors.full_messages.each do |message| %&gt;
        &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
      &lt;% end %&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;% end %&gt;

  &lt;div class="form-group"&gt;
    &lt;%= f.label :area %&gt;&lt;br&gt;
    &lt;%= f.text_field :area , class: "form-control"%&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;%= f.label :address %&gt;&lt;br&gt;
    &lt;%= f.text_field :address , class: "form-control"%&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;%= f.label :code %&gt;&lt;br&gt;
    &lt;%= f.text_field :code , class: "form-control"%&gt;
  &lt;/div&gt;
   &lt;div class="form-group"&gt;
    &lt;%= f.label :ext %&gt;&lt;br&gt;
    &lt;%= f.text_field :ext , class: "form-control"%&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;%= f.label :type %&gt;&lt;br&gt;
    &lt;%= f.collection_select(:type, CompanyEntity.space_types, :first, :last, {prompt: "Select a category"}, {class: "form-control"}) %&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;%= f.label :city_id %&gt;&lt;br&gt;
    &lt;%= f.collection_select(:city_id, City.all, :id, :name, {prompt: "Select a City"}, {class: "form-control"}) %&gt;
  &lt;/div&gt;
 &lt;/div&gt;  
&lt;div class="box-footer" &gt;
    &lt;%= f.submit "Save", class: "btn btn-primary " %&gt;
  &lt;/div&gt;
&lt;% end %&gt;
</code></pre>

<p>
</p>

<p><strong>Debug trace in log</strong> </p>

<pre><code>    Started GET "/company_entities/new" for 106.51.225.130 at 2016-03-07 01:41:37 -0500 I,
    [2016-03-07T01:41:37.643152 #19039]  INFO -- : Processing by CompanyEntitiesController#new as HTML I,
    [2016-03-07T01:41:37.668663 #19039]  INFO -- :   Rendered company_entities/_form.html.erb (11.4ms) I,
    [2016-03-07T01:41:37.668962 #19039]  INFO -- :   Rendered company_entities/new.html.erb within layouts/admin_lte_2 (14.7ms)E,
    [2016-03-07T01:41:37.669333 #19039] ERROR -- : Caught exception : ArgumentError : First argument in form cannot contain nil or be empty E,
    [2016-03-07T01:41:37.669407 #19039] ERROR -- : /home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/helpers/form_helper.rb:423:in `form_for'
/home/bobdiya/apps/2dotO_staging/releases/20160307064025/app/views/company_entities/_form.html.erb:5:in `_app_views_company_entities__form_html_erb__779177916647948870_62782300'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/template.rb:145:in `block in render'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.12/lib/active_support/notifications.rb:161:in `instrument'
/home/bobdiya/apps/2dotO_staging/shared/bundle/ruby/2.0.0/gems/actionview-4.1.12/lib/action_view/template.rb:339:in `instrument'I,


    [2016-03-07T01:41:37.670276 #19039]  INFO -- :   Rendered text template (0.0ms)
I, 
   [2016-03-07T01:41:37.670584 #19039]  INFO -- : Completed 500 Internal Server Error in 27ms (Views: 0.7ms)
I, 
   [2016-03-07T01:41:37.790672 #19036]  INFO -- : Started GET "/favicon.ico" for 106.51.225.130 at 2016-03-07 01:41:37 -0500
I, 
   [2016-03-07T01:41:37.806287 #19036]  INFO -- : Processing by ApplicationController#no_route as 
I, 
   [2016-03-07T01:41:37.806478 #19036]  INFO -- :   Parameters: {"unmatched_route"=&gt;"favicon"}
I, 
   [2016-03-07T01:41:37.817066 #19036]  INFO -- :   Rendered application/no_route.html.erb within layouts/admin_lte_2 (3.3ms)
I, 


[2016-03-07T01:41:38.947676 #19036]  INFO -- :   Rendered layouts/_notification.html.erb (5.9ms)
I, [2016-03-07T01:41:38.949171 #19036]  INFO -- :   Rendered layouts/_admin_lte_2_header.html.erb (11.9ms)
I, [2016-03-07T01:41:38.962706 #19036]  INFO -- :   Rendered layouts/_admin_lte_2_sidebar.html.erb (10.3ms)
I, [2016-03-07T01:41:38.973312 #19036]  INFO -- :   Rendered popups/_add_new_contact.html.erb (7.6ms)
I, [2016-03-07T01:41:38.974101 #19036]  INFO -- : Completed 200 OK in 1167ms (Views: 1166.7ms)
</code></pre>

<p><strong>Note</strong>: I've renamed <code>new</code> to <code>new1</code> and changed the routing preference and with the same code in controller and view - it worked!</p>