I have a Rails 2 app that uses 2dc_jqgrid and thus squirrel to build jqgrids.
Now looking to move to Rails 3, but I see that squirrel is not coming over.
[ http://robots.thoughtbot.com/post/687890317/the-road-to-rails-3 ]
It seems that squirrel is mainly used for paginate by 2dc_jqgrid.
There are some alternate branches for 2dc_jqgrid - some even labelled rails3 - hopefully one of them will do.
So, any tips/clues on the best way to find the right branch...
Thanks in advance, Chris.
rails3 compatible jqgrid plugins:
https://github.com/doabit/jqgrid-rails3
https://github.com/davebaldwin/jqgrid-rails3 (detailed usage)
https://github.com/springbok/jqgrid-rails3
Looks like this fork might be Rails 3 compatible...
https://github.com/darmou/2dc_jqgrid
Related
So in Rails 4 the long desired feature to use not queries has been added.
Article.where.not(title: 'Rails 3')
Has similar support been added for or queries, or are they planning to make it. I couldn't find anything by browsing through the release notes.
Obviously I tried
Article.where(title: 'Rails 3').or(title: 'Rails 4')
But that does not work.
Article.where(title: ['Rails 3', 'Rails 4'])
is how you'd do that in Active Record.
It's not possible to replicate any arbitrary SQL query using "Rails-y" syntax. But you can always just pass in literal sql.
So you could also do:
Article.where("articles.title = 'Rails 3' OR articles.title = 'Rails 4'")
This now works in Rails 5:
Article.where(title: 'Rails 3').or(Article.where(title: 'Rails 4'))
Code example in Rails's source.
The most common alternative is already answer by #gregates
Recently there has been pull request in rails source
Add #any_of query method to active_record
Which adds or functionality to activerecord
the contributor has already created a gem incase its not accepted
its rails 3.2 and 4 compatible
https://github.com/oelmekki/activerecord_any_of
I havent tried it yet but soon wish to use it looks good to me.
I know that this is an old thread, but anyone else looking for a solution to this problem might find this code helpful:
Article.where(title: ["Rails 3", "Rails 4"])
Maybe that will help you get someone going in the right direction without having to risk sql injection.
It seems that the rails master branch is now supporting OR queries. https://github.com/rails/rails/pull/16052
I assume it will be in the framework with the next major release.
Rails 5 will support it but you can use this backport for Rails 4.2 : https://github.com/Eric-Guo/where-or
When I do a:
rails generate migration xxx
I get : ... create db/migrate/_xxx.rb
No timestamp and not any kind of numbering.
I tried:
rake db:migrate:reset -> no change
rake db:version -> correct value (20120509143011)
add config.active_record.timestamped_migration=false -> same problem (so i removed this line)
I'm using rails 3.2 - ruby 1.9.2 - rvm - mysql
Any idea?
Problem corrected ... but i'm not sure why ;-(
The last thing i did was to remove the gem "act_as_archive". then i generated a migration to remove the corresponding table and, my timestamp were back !
I did this 2 or 3 times (adding/removing the gem), and the problem is reproductible (in my project at least)
So I suppose this is a compatibility problem with acts_as_archive gem.
I hope this will help others.
The issue is the version of the 'also_migrate' gem that the acts_as_archive uses (0.35). The next version (0.36) fixes the problem. If memory serves I believe the method_missing alias was not returning a value from whatever operation it performed
I'm looking for a way to handle integer ordinalization in Ruby/Rails, ie. "st", "nd", "rd", and "th" suffixes to integers. Ruby on Rails used to extend FixNum with an "ordinalize" method, but that functionality seems to have been deprecated in version 3.
I am currently just using the source for the old Rails method, which is fine... but this seems like functionality that most scripting languages / web frameworks would have built in, and I feel like the folks behind Rails must have had a reason for deprecating the functionality (perhaps it is now available in Ruby proper?).
Please advise!
The method you want is still ordinalize.
Active_Support was refactored a bit to provide better granularity. Instead of loading in everything at once, you can select smaller chunks depending on what you need.
You can either load everything in Active_Support using require 'active_support/all', or break it down using
require 'active_support/core_ext/integer/inflections':
>> require 'active_support/core_ext/integer/inflections' #=> true
>> 1.ordinalize #=> "1st"
Lately (last I knew) there has been a trend to not modify core classes. The Rails-Core mailing list might have a better answer for this one.
It looks like that functionality was moved to Inflector from a Fixnum extension which makes sense. Hopefully someone else can confirm this.
I am creating a Symfony 1.4 project using Propel 1.5. I would like to know if this can support multiple databases
It seems that the answer is yes: take a look at this page
#config/orgdb.schema.yml
orgdb:
_attributes: {package:lib.model.orgdb} # add this line
organization:
id: ~
I am a beginner in Rails. I use 2.3.X.
I just saw Rails 3 is pre-released [edit: now in release candidate!]. I will most probably eventually switch to it.
What are the common coding habits in 2.3 I should not take, so that the switch is as smooth as possible ?
Edit:
I've done my homework and read the Release notes. But they are far from clear for the most crucial points, for example :
1.5 New APIs
Both the router and query interface have seen significant, breaking changes. There is a backwards compatibility layer that is in place and will be supported until the 3.1 release.
This is not comprehensive enough for a beginner like me. What will break ? What could I do already in 2.3.X to avoid having troubles later ?
Looking at my personal coding habits (I have been using Rails since 1.2.x), here's a list of API changes you can anticipate according to Rails 3 release notes.
find(:all)
Avoid the usage of:
Model.find(:all)
Model.find(:first)
Model.find(:last)
in favour of:
Model.all
Model.first
Model.last
Complex queries
Avoid the composition of complex queries in favor of named scopes.
Anticipate Arel
Rails 3 offers a much cleaner approach for dealing with ActiveRecord conditions and options. You can anticipate it creating custom named scopes.
class Model
named_scope :limit, lambda { |value| { :limit => value }}
end
# old way
records = Model.all(:limit => 3)
# new way
records = Model.limit(3).all
# you can also take advantage of lazy evaluation
records = Model.limit(3)
# then in your view
records.each { ... }
When upgrading to Rails 3, simply drop the named scope definition.
Constants
Avoid the usage of the following constants in favour of the corresponding Rails.x methods, already available in Rails 2.x.
RAILS_ROOT in favour of Rails.root,
RAILS_ENV in favour of Rails.env, and
RAILS_DEFAULT_LOGGER in favour of Rails.logger.
Unobtrusive Javascript
Avoid heavy JavaScript helpers in favour of unobtrusive JavaScript.
Gem dependencies
Keep your environment.rb as clean as possible in order to make easier the migration to Bundler. You can also anticipate the migration using Bundler today without Rails 3.
The release notes are the most important thing to keep an eye on. Other than that Jeremy McAnally has some neat blog posts about the whole Rails 3 thing (and has just released a gem to help you with the migration).
I'd say, read the rails release notes and see for yourself what seems the more surprising to you. A lot of stuff changed so reading this is definitively very important.