Re: [Rails-core] Change where module file goes for namespaced AR models
> On Oct 18, 2017, at 3:56 PM, Matt Wire wrote: > > Hello all! > > Because Rails apps get cluttered up rather quickly, I am proposing a change > to this Rails generator method: > > https://github.com/rails/rails/blob/master/activerecord/lib/rails/generators/active_record/model/model_generator.rb > (starting at LOC 29) > > def create_module_file > return if regular_class_path.empty? > template "module.rb", File.join("app/models", "#{class_path.join('/')}.rb") > if behavior == :invoke > end > > > > TO > > Enter co > def create_module_file > return if regular_class_path.empty? > template "module.rb", File.join("app/models", class_path, > "#{class_path.join('/')}.rb") if behavior == :invoke > end > de here... > > > Some more background and argument: > > when you do something like: > rails g model admin/dashboard > rails g model user/dashboard user/profile > > You'll get nicely namespaced AR models and tables. The AR models are placed > into a sub-directory within the models directory and a module is placed into > the root model directory. The module only contains the table_name_prefix. So > why not put that module into the sub-directory with the model(s)? For concreteness, are you suggesting that the first command there generate the file at `app/models/admin/admin.rb`? AFAIK that’s not going to work with the existing autoloader - it won’t look there by default, and it would expect a file located there to define a class or module named `Admin::Admin` if it did. —Matt Jones -- 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.
[Rails-core] Allow to use rails style on queries with specific order
I have a situation which I need use a specific order for queries which the attributes are an enum, something like this: *.order("x.status = 5, x.status = 1, x.status = 6 ...")*, but it isn't the best way for readability, and I haven't found anything about how to do it on rails way. Is a big deal create this functionality on rails? Something like: *.order(status: [:removed, :new, :active, :corrupted ...])* *If yes, it's something trivial, if a haven't contributed with rails, can I help to build that? * -- 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.
Re: [Rails-core] Allow to use rails style on queries with specific order
Are you using MySQL? It has a field function that solves this https://www.w3schools.com/sql/func_mysql_field.asp You could probably do the same thing with substring index with other DBMSs. On Thu, Oct 19, 2017 at 1:30 PM Pablo Margreff wrote: > I have a situation which I need use a specific order for queries which the > attributes are an enum, something like this: > *.order("x.status = 5, x.status = 1, x.status = 6 ...")*, but it isn't > the best way for readability, and I haven't found anything about how to do > it on rails way. > > Is a big deal create this functionality on rails? Something like: > *.order(status: [:removed, :new, :active, :corrupted ...])* > > *If yes, it's something trivial, if a haven't contributed with rails, can > I help to build that? * > > > > > -- > 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. > -- *Kevin D. Deisz* Localytics Software Engineer -- 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.
[Rails-core] Add option to sort by an attribute before validation of has_many members with indexed errors
I would like to introduce an option *order_before_validation* for *has_many* associations: If you add new objects via an Rails API to an `has_many` association via nested attributes and you would like to keep the order of the collection sorted by an attribute the matching of the errors via `index_errors` to form input´s can be hard. You can add an `order` attribute that you set manually on client side after re-ordering or adding new items and order the collection before validation. Validation errors can easily assigned to the associated input´s in the form via the index. Do you think it it worthy merging into Rails Core? https://github.com/andre1810/rails/tree/order_before_validation_option Best regards André -- 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.
[Rails-core] Re: Allow to use rails style on queries with specific order
I just meet the same problem like you ORDER_PRIORITIES = [:removed, :new, :active, :corrupted] def self.priorities_based_order conditions = ORDER_PRIORITIES.each_with_index.map { |value, index| "WHEN #{value} THEN #{index} ELSE 999" }.join("\n") # I want other statuses to be sorted lastly, you can also use FIELD function in MySQL order_by("CASE `#{table_name}`.`status` #{conditions} END") end # usage: user.orders.priorities_based_order The above codes not run yet but I think it must work. 在 2017年10月20日星期五 UTC+8上午1:30:35,Pablo Margreff写道: > > I have a situation which I need use a specific order for queries which the > attributes are an enum, something like this: > *.order("x.status = 5, x.status = 1, x.status = 6 ...")*, but it isn't > the best way for readability, and I haven't found anything about how to do > it on rails way. > > Is a big deal create this functionality on rails? Something like: > *.order(status: [:removed, :new, :active, :corrupted ...])* > > *If yes, it's something trivial, if a haven't contributed with rails, can > I help to build that? * > > > > > -- 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.