Rails generator model with optional validations and required?
10 views
Skip to first unread message
Emile Bosch
unread,
Aug 29, 2019, 5:55:17 AM8/29/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
Hi there,
Like numerous times I am generating models, I go in to make fields required and validates_presence_of them.
Would it be easy if we could just say:
~~
rails g model contact *name *email:string *age:int
~~
Simple but super easy to add and makes it all a bit more dry.
Let me know what ya'll think and then I'll add it to rails <3
Hamad Al-Ghanim
unread,
Aug 29, 2019, 11:07:01 AM8/29/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
I would rather have it look like the following
Rails g model contact name:string:required age:int:required
Emile Bosch
unread,
Aug 29, 2019, 11:13:03 AM8/29/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Thanks for your participation!
Hmm, maybe. However I am afraid this might get a bit cumbersome when writing more then 4 fields. The word required in this sample is
the longest word of this command. Maybe req? Are there any other generators out there that tackle this problem?
Also an * (asterisk) is universal hint that something is required
> On 29 Aug 2019, at 17:07, Hamad Al-Ghanim <dreame...@gmail.com> wrote:
>
> I would rather have it look like the following
>
> Rails g model contact name:string:required age:int:required
>
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
An asterisk is actually going to be very painful to use, because your
shell is going to treat it as a shell expansion by default rather than
passing it along to Rails.