There is one http://localhost:3000/me/posts/new?type=note
I want to create a model by the params type
in my controller and I have a model named Post::Note.
so how to create it by params[:type] string ?
Try this:
note_klass = params[:type].camelize.constantize
note = note_klass.new
If your Note
class is not global, you can use this:
const_name = params[:type].camelize
note_klass = Post.const_get(const_name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With