How can i generate mongoid.yml config in Rail 2.3.5? - ruby-on-rails

As the title says, how can i generate the default mongoid.yml config file on Rail 2.3.5?
I try to use the ´rails generate mongoid:config´ command but it just generates a new app.
And also, I would like to use has_many in mongoid without embedding the associated model in the same field. I would like them to be in separate fields and associated through a *_id "column". Is that possible?

You can't. The master branch of MongoID is only Rails 3 compatible. If you want use mongoID with Rails 2.3.5, you need using the 1.0.x branch of MongoID.
In this version, there are no mongoid generator. You need define you own initializer to connect with MongoDB.

Related

Ruby on rails Database setup using scaffold generator or Manually

I am new user to ruby on rails. I have some question please give the answer as early as possible
What is the Best way to Create a Database For Your Projects in Rails?
1.Scaffold generator
2.Manually Design Database​
After installing the Rails then create a project using rails new project_name then cd project_name then run rake db:create it will create a database.
You can modify database name like by default rails uses a database e.g name_development or name_production you can modify this on go to project/config/database.yml.
The rails new project_name command creates default database adapter e.g sqlite3 you can define this which adapter he use by default while rails project create.
The sqlite is a development database you should change database adapter while going to production like postgresql or mysql or mongodb...
If you need to use mysql by default then run below command
rails new project_name -d mysql
If you need to use postgresql by default then run below command
rails new project_name -d postgres
It will create a database adapter by default which you need.
Note: You can use both for a command like rake new project_name or rails new project_name
You need to the read the Rails Guides carefully for understand basic Rails. This tutorial assumes you have basic Rails knowledge.
Also here are the Rails Commands
Ruby on rails Database setup using scaffold generator or Manually
The scaffold works after create a database.
You can see the active record basics and for basic association you can see the Michael Hartley tutorial this is good tutorial for new RoR programmer.
After all you need to design manually using reference or defining by index foreign key
First of all decide what kind of database are you going to use. (Msql2 or Postgres are mostly used)
Then design the schema on a paper or anywhere else.
And whenever you're sure. Now everything comes down to 2 different things.
You want things to be created automatically. for example: Views, CRUD for database operations in controllers.
You want to control things on your own. Now create model from rails commands, write associations, and begin writing your code and define routes as well.
NOTE: Point 2 is implemented when you're going to create a custom application and you may need operations other than basic crud.
Now, you can tell us. What actually you want to achieve and people will help you.

issue using rails console building a Rails 5 api

I'm building an API with rails 5.
When I try to store a user with the Rails console I get the following error:
I cannot figure out what is the problem.
I've run the migration
set the model
added the AMS gem
added serializers
added mime types
This is my schema
In app/models/user.rb file, it must be ApplicationRecord, not applicationRecord.

Does Ruby on Rails have a way to import an existing database schema?

I know I can do a db:create and create database tables or db:migrate to a new version, however what I want to do is import the schema from an existing database (all tables) and generate models for each one.
Does ActiveRecord have the ability to do this? Thanks!
Nope. ActiveRecord is an ORM, so it doesn't have anything to do with generating database schemas or generating models. Rails doesn't have any concept of doing this, either.
You'll have to write the database migrations and do this yourself.
There's kind of a way. Create a new Rails 2.2 app (it can't be 2.3 or 3.0, the gem hasn't been updated since 2007). Then install and use the Magic Model Generator gem.
This will look at your existing database and extra all the models from it, like magic. Since the structure of basic ActiveRecord model files is pretty similar in Rails 3, you can just copy them into your current project and tweak as necessary.

Ruby On Rails ActiveRecord SQL view into schema

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql.
The problem with this is that the view is not entered into the schema. So when I need to create my test database to run my tests against the view is not created. I then need to create it by running the sql statement. Is there a way to implement SQL views elegantly in ruby on rails?
My environment:
Ruby on Rails 3.0.3
PostgreSQL 8.3
The rails_sql_views gem is intended to solve this problem. It adds support to the schema dumper to include views, which means you can use them in your test database. I'm not sure how well it works in Rails 3, but the github issues list has a pull request that appears to add Rails 3 support.
Possibly. using config.active_record.schema_format = :sql may help.

Infer associations/validations from existing database in Rails 3

Does Magic Model Generator work under Rails 3.0? I can't make it work, the install instructions that I found, doesn't help me.
Does exist an alternative to Magic Model Generator that can infer validations and associations from an existing database?
Thanx!
Looks like the MMG is abandoned -- it doesn't even work for Rails 2.3. However -- you could create a Rails 2.2 app and use it with MMG, then use the models in your Rails 3 app.
http://github.com/drnic/magic_model_generator

Resources