Node creation should validate input before acting upon it

(Chris Giddings) #1

Rather simply, I took verbatim code from the example created article node type:

rails g push_type:node article excerpt:text body:wysiwyg validates: { presence: true }

This obviously doesn’t create what is shown on the Nodes documentation page. Instead, separate fields are created even for { and } within the node, which would be okay if they could be easily removed.

Unfortunately, attempting to remove the node using rails d push_type:node article does not work and throws all kinds of unexpected character warnings.

I would suggest having the gem do some kind of idiot validation before it takes action. My $0.02 USD.

(Aaron Russell) #2

There’s no where in the documentation that says you can include validations in the generators. The generators are just built on top of Rails’ own, which also don’t validate for this kind of input.

Try generating a normal rails model:

rails g model foo_bar title:string validates: { presence: true }

and you’ll see the generated migrations also includes a field for { and } etc.

Whilst I agree it would be nice to validate for input errors here, I consider it probably a more hassle than it’s worth job. If rails ever do this to their built in generators, there will probably be very easy ways to use their approach rather than worrying about this ourselves.

(Chris Giddings) #3

I’ll get on them for that then. :-p