I have a Client resource with 2 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'm trying to edit a client's details and I submit the changes, I get param is missing or the value is empty: client. The route from where I'm getting this error is .../companies/3.
Any help on this noobie question? Thanks!