Skip to content

Instantly share code, notes, and snippets.

@biographie
Created July 21, 2013 17:27
Show Gist options
  • Save biographie/6049235 to your computer and use it in GitHub Desktop.
Save biographie/6049235 to your computer and use it in GitHub Desktop.
ActiveRecord::RecordNotFound in CompaniesController#edit Couldn't find Company without an ID
class CompaniesController < ApplicationController
def index
@companies = Company.paginate(page: params[:page])
@due_today = Task.where(:due_date => Time.now.beginning_of_day..Time.now.end_of_day)
# @disable_nav = true to stop a partial from displaying in a certain page using unless in application.html.erb
end
def new
@company = Company.new
@company.phone_numbers.build
end
def show
@company = Company.find(params[:id])
end
def create
@company = Company.create(params[:company])
if @company.save
redirect_to "/companies"
else
render 'new'
end
end
def edit
@company = Company.find(params[:company])
end
end
<%= form_for(@company) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, :class => "input-width bottom-border" %>
<%= f.label :address %>
<%= f.text_field :address, :class => "input-width" %>
<%= f.label :email %>
<%= f.text_field :email, :class => "input-width" %>
<div class="items">
<a href="#" class="add">add phone</a>
<%= f.nested_fields_for :phone_numbers do |f|
render 'phone', f: f
end %>
</div>
<%= f.label :background, :class => "remember" %>
<%= f.text_area :background, :class => "bg-width text-area-height" %>
<%= f.submit "Add Company", class: "btn btn-large btn-info btn-height" %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment