Adding an ORM to an existing padrino application - ruby

I'm new to ruby, sinatra and padrino,
so it might be a silly question, but:
Is there a way to add an orm to an existing application ?
My problem is that I have created an application with the following command line:
$ padrino-gen project sample_blog -a mysql -b
(I thought that a default ORM was selected.)
Then tried to add a model:
$ padrino-gen model post title:string body:text
<= You need an ORM adapter for run this generator. Sorry!
How can I add the orm without recreatting the whole application?
It's not very important now, since the application do not contains anything,
but I plan latter to add tests, and I would like to know if it's easy.
Thanks for your tips for a beginner.

Open /project-name/.components with your editor and add
:orm: activerecord

Related

rails generate ckeditor:install --orm=active_record --backend=active_storag not worked Rails 5

I want to use in my project ckeditor with active storage, but when I generate to install ckeditor using orm active record and active storage, it create an initializer but not create any migration file.
Running via Spring preloader in process 23128
create config/initializers/ckeditor.rb
route mount Ckeditor::Engine => '/ckeditor'
Could not find "active_record/active_storage/ckeditor/asset.rb" in
any of your source paths. Your current source paths are:
/home/arif/Development/Test
Project/cable_test/lib/templates/ckeditor/install
/home/arif/.rvm/gems/ruby-2.4.2/gems/ckeditor-
4.1.3/lib/generators/ckeditor/templates
So I ran into this as well, and after poking around the code I figured I'd just run the generator without the flags like the docs. If you run into this problem just run the generator with no flags rails g ckeditor:install. Also, you'll need to look at these files and make sure your models match.
https://github.com/galetahub/ckeditor/tree/master/lib/generators/ckeditor/templates/active_record/active_storage/ckeditor
EDIT: It looks like active_storage is only available on the master branch as of this post.

How to add migration details to its corresponding model in Rails 4

I remember one of my colleagues did this but I don't remember how. Guess he used some gem or a rake task to achieve this.
Please share if you know how to do this.
Maybe even a gem that can add relevant associations automatically to the model file. This when we do rails g model.
You can use this gem:
https://github.com/ctran/annotate_models
Then run annotate from the terminal. It notes if the field is hstore or array type in case of postgresql. So it is very intelligent. Even myself made a commit to it ;)

Sequel model doesn't find connection defined in a Sinatra app file

I'm building a simple Sinatra application to show some items stored in a database. I happened to find the gem sinatra-sequel that was supposed to make things easier.
To mantain the modularity I'm defining the Sinatra app in a file and the model in a different file. Unfortunately the model can't find the connection and mais my app crash. The same thing is described in this sequel-sinatra issue
I could define my model in the app class, but I prefer a more elegant solution if there is any.

Using Padrino and DataMapper to access an existing Database

I'm migrating a sinatra app I have that acts as a backend UI for our DNS database. I've already got the DM configs in the sinatra app but want to migrate it to padrino so I can make it cleaner and easier to read, but also because I want to play around to padrino. If I just generate a new model, can I perform the datamapper mapping in that model, including specifying the db application and get away with doing that instead of using a generator?
What do I need to do to be able to access models on a different database, ideally without damaging that data base (read only)
Right so you actually can do this I found out with a bit of trial and error. Specify the datamapper database source in the config/boot.rb there's a section labelled Padrino.after_load, you'll want to add in your new DataMapper source here
DataMapper.setup(:myalternatedatasource, "MY_ALTERNATE_DB_URL
Then in your model file you'll want to specify
def self.default_repository_name
:myalternatedatasource
end
And it'll all work as intended!

How to override 'where' in rails 3

I have upgraded my application from rails 2.3.8 to 3.0.3 . But I'm facing a problem. I was using 'find' but the overriding doesn't work in rails 3:
# override activerecord's find to allow us to find by name or id transparently
def self.find(*args)
if args.is_a?(Array) and args.first.is_a?(String) and (args.first.index(/[a-zA-Z\-_]+/) or args.first.to_i.eql?(0) )
find_by_login_slug(args)
else
super
end
end
I'm wondering if there is a way to make this work in rails 3 or even by using where instead.
thanks
The problem you're are facing is an upgrading from a rails 2.3.X to a rails 3.0.X application. Although, it could seem a simple task it isn't, especially if you have a real application and not a toy one. I suggest you to take a look to a screencast series from Rayn Bates, you could start from http://railscasts.com/episodes/225-upgrading-to-rails-3-part-1 to get a complete idea off the problem you are facing.
If you only need to read about ActiveRecord new interface http://m.onkey.org/active-record-query-interface is a great article.

Resources