i'm newbie in rails. i have problem with how to connect rails with
database. before i can connect it with command
"rake db:create" to create database.
and "rake db:migrate" to migrate schema to database.
but, i want to connect rails with database that i have before, not
create it via rails. can you help me?
i'm newbie in rails. i have problem with how to connect rails with
database. before i can connect it with command
"rake db:create" to create database.
and "rake db:migrate" to migrate schema to database.
but, i want to connect rails with database that i have before, not
create it via rails. can you help me?
just setup your config/database.yml and that should work. however, when
you want to collaborate with someone, you have to depend on schema.rb
rather than migrations to create the database.
i have been setup database.yml, with same name database that i want to
use.
but then what i should do?
Should i to run "rails generate scaffold"?
let say my command
"rails generate scaffold members name:string email:string" to create
schema??
and then run "rake db:migrate"?
end
----------------------------------------------------------
it say create_table "name of table", but the problem is i have been have
that table in my database, and i didn't want to change that table.
first run rake db:schema:dump to generate your schema from the current
database.
Then if you want to run a scaffold (I've just tested this one, I don't
actually use
scaffold), use
rails g scaffold <singular_table_name> --migration false
i can't understand this command
"rails g scaffold <singular_table_name> --migration false"
can you describe it more?
if you have a table called comments in your current database, and you want
to generate
the model, controller and views for that table, you need to run
rails g scaffold comment
but that will generate a migration file for creating the table on the db.
since you
already have the tables, you can pass --migration false to skip creating
the migration.
I always see, every table in rails given the name of the plural form.
however I have a table with a singular form. let say my table name
"member" not "members", could this create problems?
then the rails command writing table name usually begins with a capital
letter and using the singular form. Can I have a table named in the
singular form, and run the command with the same name?
I have tried, but it can not display the contents of my database. there
are things that make me confused, it was formed six lines of command
"show, edit, and destroy", an amount equal to the number of records in
the table "member". but does not display the contents of the table
"member" it.
I always see, every table in rails given the name of the plural form.
however I have a table with a singular form. let say my table name
"member" not "members", could this create problems?
then the rails command writing table name usually begins with a capital
letter and using the singular form. Can I have a table named in the
singular form, and run the command with the same name?
I have tried, but it can not display the contents of my database. there
are things that make me confused, it was formed six lines of command
"show, edit, and destroy", an amount equal to the number of records in
the table "member". but does not display the contents of the table
"member" it.
try looking for set_table_name syntax to set the table name that you want
to use
that the code of anggota_controller.rb
-----------------------------------------
Where do you use the member table? I think you need to read on the MVC
architecture first before you start working on this one. I really can't
help you
if you have no firsthand knowledge of how the models and controllers are
connected.
no, i didn't use member table, i use member word just to describe to you
singular and plural form. because i little confuse tell you plural form
from word "anggota"
no, i didn't use member table, i use member word just to describe to you
singular and plural form. because i little confuse tell you plural form
from word "anggota"
ok. Just make sure that you're using the table name on the db on the
Anggota
model. If you're doing that and still gets errors, I don't know what your
issue is.
I can't see any errors on your controller. It seems like it's the one
generated by
the scaffold generator so there shouldn't be any errors in there.
Try running the console and see if Anggota.first retrieves the first record.
1. Rails new First_app
2. Change config database.yml
3. Rake db:schema:dump
4. Rails g scaffold Anggota –migration false
5. Change First_app\app\model\anggotum.rb with this syntax
1. Rails new First_app
2. Change config database.yml
3. Rake db:schema:dump
4. Rails g scaffold Anggota –migration false
5. Change First_app\app\model\anggotum.rb with this syntax
-------------------------------------
class Anggotum < ActiveRecord::Base
set_table_name "anggota"
end
---------------------------------------
i have try to make new rails app, and that is the step by step that i
did.
did i do wrong step??
everything looks ok. did you try it on the console?