I have a client resource with two types: Person and Company.
routes.rb:
resources :clients
resources :people, :controller => "clients", :type => "Person"
resources :companies, :controller => "clients", :type => "Company"
clients_controller:
def new
@client = Client.new()
@client.type = params[:type]
end
def create
@client = current_partner.clients.new(client_params)
if @client.save
redirect_to clients_path
...
end
...
private
def client_params
params.require(:client).permit(:type, :partner_id, :name, :email, :phone, :cui, :registration_id, :address)
end
def find_client
@client ||= Client.find(params[:id])
end
client.rb
class Client < ActiveRecord::Base
validates_presence_of :type
CLIENT_TYPES = ['Person', 'Company']
end
person.rb
class Person < Client
validates_presence_of :name, :email, :phone
end
compay.rb
class Company < Client
validates_presence_of :name, :email, :cui, :registration_id, :phone
validates_uniqueness_of :cui, :registration_id, uniqueness: {scope: :partner_id}
end
The problem is when I try to edit the client details, and I submit the changes, I get the parameter is missing or the value is empty: the client. The route where I get this error is ... / company / 3.
Any help on this noobie? Thank!