Hello,

I've got some experience in Java, and recently, I've begun to practice
with Rails.

One of the things that has surprised to me, after I've read some books,
it's that classes hasn't got attributes; the attributes are in the files
db/migrate/*. After that, the ORM makes the mapping with de Database.
But the attributes aren't in the files app/models/*.

It's difficult to me see the class without attributes; in Java is
different. Is there anything bad in this idea?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Hassan Schroeder at Jul 21, 2012 at 1:29 pm

    On Sat, Jul 21, 2012 at 3:54 AM, Cortomix aa wrote:

    One of the things that has surprised to me, after I've read some books,
    it's that classes hasn't got attributes; the attributes are in the files
    db/migrate/*. After that, the ORM makes the mapping with de Database.
    But the attributes aren't in the files app/models/*.
    Not all classes in a Rails app inherit from ActiveRecord::Base :-)
    And you can have attributes that come from mixed-in modules. It's
    not all about an ORM mapping.
    It's difficult to me see the class without attributes; in Java is
    different. Is there anything bad in this idea?
    Sorry, I'm not sure what you're asking.

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Cortomix aa at Jul 21, 2012 at 3:20 pm
    Thank you for your answer Hassan,

    I explain my problem. If I've got a Person class in my model, with
    Rails I will have a class CreatePersons (for example) in db/migrate/
    with its attributes (name, address, telephone...)

    class CreatePersons< ActiveRecord::Migration
    def change
    create_table :persons do |t|
    t.string :name
    t.string :address
    .....

    t.timestamps
    end
    end
    end



    And I'll have the class Person in app/models, but in this class, I
    mustn't put the attributes name, address...


    class Persona < ActiveRecord::Base
    end


    If I work with the Person class, I will have a class without attributes
    name or address!!

    Is it right what I've told? Or, haven't I understood de idea in Rails?

    Thanks!

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Hassan Schroeder at Jul 21, 2012 at 3:34 pm

    On Sat, Jul 21, 2012 at 8:20 AM, Cortomix aa wrote:

    I explain my problem. If I've got a Person class in my model, with
    Rails I will have a class CreatePersons (for example) in db/migrate/
    with its attributes (name, address, telephone...)
    Which is only used to create the database table, and which may be
    overridden by later migrations. Once used, it's meaningless, other
    than documenting the history of development.
    class Persona < ActiveRecord::Base
    end
    If I work with the Person class, I will have a class without attributes
    name or address!!
    The class has those attributes; what makes you think it doesn't? It
    just isn't necessary for them to be written in the file that defines the
    class for them to exist; ActiveRecord derives them from the schema
    of the database.

    Open up a console session and play with it.
    person = Person.new
    person.name= "Bob"
    person.name
    => "Bob"

    Create a non-AR class and experiment with it. Learning through
    interactive exploring is one of the advantages of Ruby over Java :-)

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJul 21, '12 at 10:54a
activeJul 21, '12 at 3:34p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Hassan Schroeder: 2 posts Cortomix aa: 2 posts

People

Translate

site design / logo © 2021 Grokbase