Rails: Removing migrations/schema created by gem on uninstall - ruby-on-rails

Is there an easy way to drop tables created by a gem when I am installing it? For my specific case I want to uninstall the gem and reinstall it but the old tables and data are still there. Right now I plan on dropping the created tables manually. Is there a way to see all the tables created by a gem?

There is no easy way to see all the tables created by a gem, unless they're namespaced within something sensible. For example, Forem namespaces all the tables with a forem_ prefix.
You would need to create a migration and drop the tables manually.

Related

rails 4 app with 2 databases: MySQL and Cassandra - where to begin?

Hi have an existing rails 4 app which is using a MySQL database.
I now need to add code that creates dynamically a new table for every object and its attributes.
I decided to use a No SQL solution for this. Initially I wanted to use Mongo DB since I was familair with this. However, my company supports only Cassandra/redis/solr. So I have to pick one of these.
I chose Cassandra but Im not finding any tutorials or examples on how to use it with an existing rails app with a MySQL DB.
I found this ORM for rails-Cassandra but no idea how to make it work with an existing Active record - mysql system.
Any ideas would be very appreciated.
Apologize this post has no code. But I couldnt find any answers for this issue on SO so please excuse if any mistakes.
thanks
ActiveRecord and Cequel will be independent.
As shown in their docs you extend a model's functionality by including the Cequel::Record module.
include Cequel::Record
In order to use it in rails you (obviously) need to add the proper gem in your Gemfile
gem 'cequel'
and create the configuration for the project
bundle exec rake cequel:keyspace:create
After that, you will have a config/cequel.yml from where you will define your settings (as you did in config/database.yml for your MySQL)
MySQL models will still use the ActiveRecord
class Foo < ActiveRecord::Base
...
end
while Cassandra ones will use the Cequel
class Bar
include Cequel::Record
...
end

Rails migration for updated gem

We have this gem that recently got a version boost which included a lot of new migrations.
What seems to be the consensus when running new migrations on apps with existing installations without having to wipe the database and start again?
At the moment our install_generator just copies in the updated migration.rb file but immediately conflicts with apps that already have the old tables.
So I'm looking for the cleanest way to handle gem updates that include new migrations.
Migrations inside gems are supposed to be written in a way such that while running new migrations, you don't have to delete old tables. Which gem are you using?

Is it possible to add globalize3 to an external ActiveRecord model class?

I have a project for which I'm using the globalize3 gem to allow for multiple languages. In my own models I just add 'translates field1, field2, etc.' and the appropriate migrations and it is all working great.
The problems is that I also have some functionality that depends on external gems. For some of those models I would like to add globalize too. I don't have the code for the models to modify directly like I did with the others. Reopening the model doesn't seem to work. Is there a way to add that translates line to models that I don't have direct access to ?
I'm using Rails 3.1 and Ruby 1.9.2 in case it matters.
Could you supply the name of the gem and a model from that gem?
Are the classes namespaced under a module? If so, you may not be re-opening the classes correctly. I use the qwandry gem to examine gems that I've included in my project, so that might be helpful in determining this. Of course looking at the source on the project's site is also good if it's available.
I assume that what happens when you say it isn't working is that the I18n.locale setting doesn't affect setting/getting the fields, correct? It would probably complain about there not being a table if it was working but you hadn't yet created the tables.

Sharing models between Rails apps using gems

So I'd like to share models between two Rails apps and do not like the submodules solution (burned me in the past). I'm thinking about using gems to solve this and have this basically working:
Create a gem using jeweler (my_models)
Create a rails app with something in the Gemfile like:
gem 'my_models', :path => '../my_models' so you can avoid constantly packaging the gem, etc.
Use shotgun to constantly reload all the classes (otherwise you can't really edit my_models files without restarting the server/console each time.
So a few questions:
Shotgun is slow, is there a better way in Rails to reload just that one gem each time?
If my my_models ActiveRecord models have dependencies, I put them in my_models gems, will that cause dependency nightmares in my regular app?
What else am I missing on why this could be a bad idea?
If you use a VCS with submodules support (like Git) you could just put models into a different repository and make it a submodule of your Rails apps. That would give you an almost effortless code sharing - Rails wouldn't even know that you are cheating.

What's your solution for 'contact forms' in Ruby on Rails applications?

With a quick Google search, one can find literally hundreds of examples for contact forms using PHP and/or JavaScript, but there don't seem to be any "ready-made" contact forms for Ruby on Rails. Do they exist? What do you use for contact forms in your Ruby on Rails apps?
Personally, I use an ActiveRecord model for mine as I like to keep a store of messages being sent, and then use an ActionMailer after saving a record to send an email.
Alternatively there is a gem called MailForm which allows you to build a form model without a database table, which will work with other gems such as Formtastic.
As for ready-made contact forms, I don't know of any (though they may well exist) as it's not particularly time-consuming to build one from scratch.
I was running into the same issue with wanting an easy to use out of the box Contact Form, but wasn't able to find one. So I've written ContactUs a Rails Engine that you can easily drop into any Rails 3+ application. I tried to keep it dead simple and as easily configurable as possible. It does require the Formtastic gem since I wanted an easy way to hook into peoples existing form styles though.
To install the Engine add the contact_us gem to your Gemfile:
gem 'contact_us', '~> 0.1.3'
Run bundle and the install rake task:
$ bundle
$ bundle exec rake contact_us:install
Then just modify the generated initializer in /config/initializers/contact_us.rb to have the email you want the form submissions sent to.

Resources