I don’t think we’d like to autogenerate scopes for your models based on the 
column type, no.


You might want to look into using an enum 
<http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html> backed by an 
integer ”status” column instead of the boolean column.

That generates a scope as well as making it really easy to add another state, 
should you need ever need to do so.

> Den 4. jan. 2018 kl. 13.16 skrev Léo Santos <aleot...@gmail.com>:
> 
> Hi there!
> 
> I would like to introduce a feature that can expedite development, which by 
> the way I think it's one of the greatest advantages of using Ruby on Rails. 
> So, looking to follow the Convention Over Configuration standard, lets say 
> you have:
> 
> # a users table
> create_table "users", force: true do |t|
>   t.boolean  "active", default: true
> end
> 
> # a User model
> class User < ActiveRecord::Base
> end
> 
> The new feature would automatically add the scope to fetch active users like:
> 
>    >User.active
> 
> without having to explicitly define it on the model. It is similar to a 
> feature that has already been implemented to boolean attributes that allow us 
> to do things like:
> 
>       >user = User.new(active: true)
>    >user.active? 
>      #=> true 
> 
> Do you think it's worthy merging it into Rails core?
> 
> Best regards,
> Leonardo Santos
> 
> -- 
> 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 rubyonrails-core+unsubscr...@googlegroups.com 
> <mailto:rubyonrails-core+unsubscr...@googlegroups.com>.
> To post to this group, send email to rubyonrails-core@googlegroups.com 
> <mailto:rubyonrails-core@googlegroups.com>.
> Visit this group at https://groups.google.com/group/rubyonrails-core 
> <https://groups.google.com/group/rubyonrails-core>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

--
Kasper

-- 
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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to