Rails generator model with optional validations and required?

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

Rails generator model with optional validations and required?

emile
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/f366109c-2326-49b0-b82a-e2712b7668a7%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Rails generator model with optional validations and required?

Hamad Al-Ghanim
I would rather have it look like the following

Rails g model contact name:string:required age:int:required

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/bf680441-891b-4494-aa64-c5d8b518de34%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Rails generator model with optional validations and required?

emile
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 <[hidden email]> wrote:
>
> I would rather have it look like the following
>
> Rails g model contact name:string:required age:int:required
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/PUGFir_OJ30/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/bf680441-891b-4494-aa64-c5d8b518de34%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/AEB61F46-2823-4425-A4D3-480C90CCEAA4%4054hrs.com.
Reply | Threaded
Open this post in threaded view
|

Re: Rails generator model with optional validations and required?

James Coleman
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.

On Thu, Aug 29, 2019 at 11:13 AM Emile Bosch <[hidden email]> wrote:

>
> 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 <[hidden email]> wrote:
> >
> > I would rather have it look like the following
> >
> > Rails g model contact name:string:required age:int:required
> >
> > --
> > You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/PUGFir_OJ30/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to [hidden email].
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/bf680441-891b-4494-aa64-c5d8b518de34%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/AEB61F46-2823-4425-A4D3-480C90CCEAA4%4054hrs.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAAaqYe9CYwKN9PE4tV-%2BySbNrddYK7Wu2ZZmJUYkdCSd%3D6CVoA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Rails generator model with optional validations and required?

emile
Ha, well that makes the choice easy then, then :required is probably the way to go.

> On 29 Aug 2019, at 17:17, James Coleman <[hidden email]> wrote:
>
> 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.
>
> On Thu, Aug 29, 2019 at 11:13 AM Emile Bosch <[hidden email]> wrote:
>>
>> 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 <[hidden email]> wrote:
>>>
>>> I would rather have it look like the following
>>>
>>> Rails g model contact name:string:required age:int:required
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/PUGFir_OJ30/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to [hidden email].
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/bf680441-891b-4494-aa64-c5d8b518de34%40googlegroups.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
>> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/AEB61F46-2823-4425-A4D3-480C90CCEAA4%4054hrs.com.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/PUGFir_OJ30/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAAaqYe9CYwKN9PE4tV-%2BySbNrddYK7Wu2ZZmJUYkdCSd%3D6CVoA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/FC38FEED-7C54-419D-BDEC-6F87A97B530F%4054hrs.com.