views:

43

answers:

1

Hi,

I just succeed to set in place my rails server. But when I'm trying to add a new "machine" I have an error. I can see this in logs

ActionView::TemplateError (undefined method `owner_id' for #<Machine:0x7f85a0d279e0>) on line #49 of app/views/machines/_form.html.erb:
46: </div>
47: <p>
48:    <%= f_machine.label :owner %><br />
49:    <%= f_machine.collection_select :owner_id, Owner.find(:all), :id, :name, :prompt => "Select an owner"%>
50: </p>
51: <p>
52:    <%= f_machine.label :category %><br />

app/views/machines/_form.html.erb:49
app/views/machines/new.html.erb:4
app/views/machines/new.html.erb:3
app/controllers/machines_controller.rb:35:in `new'
passenger (2.2.15) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
passenger (2.2.15) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:441:in `start_request_handler'
passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:381:in `handle_spawn_application'
passenger (2.2.15) lib/phusion_passenger/utils.rb:252:in `safe_fork'
passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:377:in `handle_spawn_application'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:163:in `start'
passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:222:in `start'
passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rails_application'
passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:247:in `spawn_rails_application'
passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rails_application'
passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:145:in `spawn_application'
passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:278:in `handle_spawn_application'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Rendering /home/et1/wip3/sophia/public/500.html (500 Internal Server Error)

Machine/new

<h1>New machine</h1>

<% form_for(@machine) do |f_machine| %>
    <%= render :partial => 'form', :locals => { :f_machine => f_machine } %><br />
<p><br />
<%= f_machine.submit 'Create' %>
</p>
<% end %>

  <%= link_to 'Back', machines_path %>

machine/_form:

<%= f_machine.error_messages %><br />
<p>
    <%= f_machine.label :nom %><br />
    <%= f_machine.text_field :nom %>
</p>
<p>
<%= f_machine.label :role %><br />
<select name="machine[role]" title="Select a role">
    <option value="dev">Dev</option>
    <option value="test">Test</option>
    <option value="prod">Prod</option>
    <option value="Support">Support</option>
</select>

</p>

<div class="fields">

<% f_machine.fields_for :ipvfours do |f_ip| %>
    <%= render :partial => 'ipvfours/form', :locals => { :f_ip => f_ip } %>     
<% end %> 
<p>
    <%= link_to_add_fields "Add IPv4 address", f_machine, :ipvfours %>
</p>


<% f_machine.fields_for :ipvsixes do |f_ip| %>
    <%= render 'ipvsixes/form', :f_ip => f_ip %> 
<% end %>

<p>
    <%= link_to_add_fields "Add IPv6 address", f_machine, :ipvsixes %>
</p>



<p>
    <% f_machine.fields_for :macs do |f_ip| %>
        <%= render 'macs/form', :f_ip => f_ip %> 
    <% end %>
</p>
<p>
    <%= link_to_add_fields "Add MAC address", f_machine, :macs %>
</p>

</div>
<p>
   <%= f_machine.label :owner %><br />
   <%= f_machine.collection_select :owner_id, Owner.find(:all), :id, :name, :prompt => "Select an owner"%>
</p>
<p>
   <%= f_machine.label :category %><br />
   <%= f_machine.collection_select :category_id, Category.find(:all), :id, :cat, :prompt => "Select a category"%>
</p>
<br />

I don't really understand why it does not work knowing that in development mode it works.

Thanks in advance for help.

+1  A: 

Have you successfully migrated your database? Is there an owner_id field in the machines table in your production database?

Gareth
This. It looks like a database schema issue. Check that you setup production database and ran all your migrations correctly
Faisal
Yes I run db migrate: rake db:migrate RAILS_ENV=production
Goueg83460
check in the database, and see if the column is actually there. There may have been a problem with how the migration ran
Gareth
ok owner_id is not in table, so it may explain the problem.
Goueg83460
now my question is: how add it to db without do it manually whit an sql browser ?? I mean I think that there a way to add with command but how ?? Thanks.
Goueg83460
you need to complete the migration. I don't know what your deployment process involves, but your best option is to SSH into your production machine, `cd` to your rails app directory and then type `rake db:migrate RAILS_ENV=production` - watching out for any errors
Gareth
I already do it. but I think that as I'm a newbie, during my first test I added manually the owner_id column in machines table. So it explain that migration do not do it. I tried to edit the migration file and add t.int owner_id. I'm using git to push and pull my change set.
Goueg83460
I think I found solution: modify migrate file, push changement and run again db:migrate RAILS_ENV=production and finally restart apache2 server
Goueg83460