Just trying to setup Rails and I have a few concerns - ruby-on-rails

I'm trying to install Rails (On Mac OSX) and I basically have it all done now, but I'm currently learning from a book that uses SQLite 3, I just want to use MySQL, will the statements for talking to the Database be the same throughout the book? Also, when you set your Mysql password/username you do so in /config/database.yml but that's visible from the web, and anybody can navigate there and see my password and what not, is there something I am missing here?

ActiveRecord will abstract any interaction with your database. As long as you use it you don't have to worry if you are on SQLite or MySQL.
The only public facing folder is the public folder. This contrasts with PHP applications where everything is exposed (and must be exposed in order for the web server to interact with it).

Related

Host multiple application under single domain

Currently I develop new app for my customer and need to integrate it with the old one.
My current app based on Ruby 1.9.3 and latest Rails version. Old app written on Ruby 1.8.7 and something like rails 3.0.11.
So my goal is to host it under one domain, so if localhost/old_controller will bring customer to some old controller, and localhost/new_controller will be handled by my application. Is it possible and how to do that? Or if it's not possible, then handle new app as a sub domain for the old one, like localhost for old one and new.localhost for my app.
Take a look at Rails Engines. Basically they are Rails Applications which can be hooked to another application.
As for the authlogic matter: If both of your apps share the same database then there shouldn't be a problem regarding the logins - provided you use gems in both apps that share the same schema they're built on.

Cucumber #javascript Breaks Oracle SQL Calls

I am using Ruby on Rails 3.0.7 Cucumber 1.0.1, and Oracle as the database. I have my own local user/schema for my development database, but I also connect to another Oracle database in a read-only fashion. Someone as my work has created a gem that allows me to talk to that other database and access its models. Let's say we call that other database Servo. Then I am able to do something like Servo::ModelName.all and all other regular calls.
The Oracle that gets generated by that is something like: SELECT * FROM "SERVO"."MODELNAMES"; Note that it appends the SERVO database name.
Now, I am writing a Cucumber test that at times, in my custom steps, uses Servo. That all works fine. The new scenario I am writing uses the #javascript tag. If any step (in the Background or in the Scenario) does not use Servo, then it runs fine. However, if I do use Servo, it breaks. The Oracle SQL being generated is suddenly SELECT * FROM "MODELNAMES"; and it is no longer aware of the other database.
So, any ideas why this is happening? Why does the #javascript suddenly change the SQL being generated? I couldn't find any good documentation about what else it does besides launching Firefox.
I'm sure others may want to know more information but I didn't want to flood this question so just let me know if you want some more details.
The main difference #javascript will introduce on the application side is that you're running a web server instead of routing requests directly through rack. I'd investigate with that knowledge and see if there isn't something you're doing in an initializer or something which could be affected by the different context.

rails mysql2 database...where is it?

yeah, it's pretty stupid. maybe i'm searching for the wrong keywords. where the hell is the db file in the rails folder? I really need to edit stuff and I think it's ridiculous I'm trying to use console and getting a shitload of errors and having trouble deleting records, of all things.
(ie if it was sqlite3, it'd be in the db folder).
....pulls hair out
Rails needs a separate mysql server running either on the same, or a different machine. MySql isn't like sqlite, which uses a text file. Check with your web host, they probably have a MySql database set up already. Use something like Sequel Pro if you want to manipulate the data directly in the database outside of rails.

How to extend an existing Ruby on Rails CMS to host multiple sites?

I am trying to build a CMS I can use to host multiple sites. I know I'm going to end up reinventing the wheel a million times with this project, so I'm thinking about extending an existing open source Ruby on Rails CMS to meet my needs.
One of those needs is to be able to run multiple sites, while using only one code-base. That way, when there's an update I want to make, I can update it in one place, and the change is reflected on all of the sites. I think that this will be able to scale by running multiple instances of the application.
I think that I can use the domain/subdomain to determine which data to display. For example, someone goes to subdomain1.mysite.com and the application looks in the database for the content for subdomain1.
The problem I see is with most pre-built CMS solutions, they are only designed to host one site, including the one I want to use. So the database is structured to work with one site. However, I had the idea that I could overcome this by "creating a new database" for each site, then specifying which database to connect to based on the domain/subdomain as I mentioned above.
I'm thinking of hosting this on Heroku, so I'm wondering what my options for this might be. I'm not very familiar with Amazon S3, or Amazon SimpleDB, but I feel like there's some sort of "cloud database" that would make this solution a lot more realistic, than creating a new MySQL database for each site.
What do you think? Am I thinking about this the wrong way? What advice do you have to offer in this area?
I've worked on a Rails app like this, and the way it was done there was named-based virtual hosts, with db entries for each site running. Each record was scoped to a site if necessary (blog posts, etc.) while users would have access to all sites running out of that db. Administrator permissions could be global or scoped to one or more sites.
You're absolutely correct when you say you'll reinvent the wheel a million times during the project. Plugins will likely require hacking on top of the CMS itself.
In my situation, it ended up being a waste of almost a million dollars of company money to build that codebase to run multiple sites while still being able to cater to the whims of each client site. It worked, but was not very maintainable due to the number of site-specific hacks that subsequently entered the codebase. You may be able to make it work if you don't have to worry about catering to specific client sites running on your platform.
In the end, you're going to need a layer of indirection to handle the different sites regardless of methodology. We ended up putting it in the database itself. If you go with the different-db-for-each-site method you mentioned, you'll put that layer in your code instead. I'm not sure which one is the better method.
I hope you're able to pull this off. I failed.
Also, as I learned today, Heroku offers postgres instead of mysql for rails apps.
There's James Stewart's Theme Support Plugin for Rails 2.3, and lucasefe's themes_for_rails gem for Rails 3+.
I just started using the 2.3 version and it's working well so far.

Freezing database with Rails application

So for a class I have to turn in my Rails application to my professor. What is the best way to make sure everything goes smoothly when he trys to start it up? Also, is there anyway I can freeze a database and send that with it so he has all of the data I have been using in the application?
Thanks a lot.
Depending on your needs, the SQLite3 database (used by default in Rails) is stored on the file system in the db directory of your Rails app. So, assuming your professor has the requirements to run Ruby on Rails, the application will start up with the data you've used.
My guess is you have hard coded connection strings in your rails application. Ask your professor what server he will be running it off of. At that point either change the strings to match or create a config file that is read in and can be edited (which is the better choice of the two). Most databases have export functionality which will allow you to export the current information within the database.

Resources