Houdini
Houdini

Reputation: 3542

Rails - using 'create' for different types of models in same controller

Here is my use case, in bullet points so its nice and easy to follow:

Thanks!

Upvotes: 0

Views: 176

Answers (1)

Avdept
Avdept

Reputation: 2289

If i understood your question correctly, you can check your params for type of new user from your radio box, and then simply call some private method and pass params into, that will create new resource depending on params.

For example

Assume you have in your params key with name of entity. You do post on create#users

def create
  if create_new_resource(params)
    redirect_to some_path
   else
    render 'new'
  end
end

private

def create_new_resource(params)
   "#{params[:entity].create(params)}" 
end

Just for as a start version. You have to do some changes aswell

Upvotes: 2

Related Questions