constantize error "wrong constant name post"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

constantize error "wrong constant name post"

fugee ohu
commentable = commentable_type.constantize.find(commentable_id)

NameError in CommentsController#new
wrong constant name post

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b2baa687-4358-4fa7-bd11-0df91c093805%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: constantize error "wrong constant name post"

Frederico Martins
Hi. Could you try the code below?

commentable = commentable_type.camelize.constantize.find(commentable_id)


On Tuesday, June 13, 2017 at 11:15:45 PM UTC-3, fugee ohu wrote:
commentable = commentable_type.constantize.find(commentable_id)

NameError in CommentsController#new
wrong constant name post

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/81558fa3-4b77-45c2-8b6e-2963d652fd3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: constantize error "wrong constant name post"

fugee ohu


On Wednesday, June 14, 2017 at 9:44:52 AM UTC-4, Frederico Martins wrote:
Hi. Could you try the code below?

commentable = commentable_type.camelize.constantize.find(commentable_id)


On Tuesday, June 13, 2017 at 11:15:45 PM UTC-3, fugee ohu wrote:
commentable = commentable_type.constantize.find(commentable_id)

NameError in CommentsController#new
wrong constant name post



I solved the problem by using values for polymorphic types that start with capital letters This looks like a better solution Thanks If constantize doesn't convert the first char to upper case then what does it do?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/aff2f9a2-f5be-4c37-8f48-f2ce3d0b3edf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: constantize error "wrong constant name post"

Frederico Martins
It only tries to find and return an available constant with the specified name. But the string needs to be already in camel case.

https://apidock.com/rails/String/constantize

On Monday, June 26, 2017 at 6:18:39 PM UTC-3, fugee ohu wrote:


On Wednesday, June 14, 2017 at 9:44:52 AM UTC-4, Frederico Martins wrote:
Hi. Could you try the code below?

commentable = commentable_type.camelize.constantize.find(commentable_id)


On Tuesday, June 13, 2017 at 11:15:45 PM UTC-3, fugee ohu wrote:
commentable = commentable_type.constantize.find(commentable_id)

NameError in CommentsController#new
wrong constant name post



I solved the problem by using values for polymorphic types that start with capital letters This looks like a better solution Thanks If constantize doesn't convert the first char to upper case then what does it do?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5651dc2f-6aca-42d6-b3ec-ddb863e89fa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.