Forum: Italian Ruby user group [Rails] Console: non riesco ad utilizzare i modelli

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Roberto C. (Guest)
on 2009-03-30 18:51
Ho creato la seguente tabella nel database dell' environment
"development":

create table students(
  id int auto_increment,
  name varchar(50) not null,
  surname varchar(50) not null,
  registered_at timestamp not null,
  class varchar(2),
  primary key(id)
);

Dopodichè ho generato il modello con il solito
$ ruby script/generate model student

Poi accedo alla console ma ottengo degli errori se cerco di utilizzare
la classe di modello generata

$ ruby script/console
>> roby = Student.new
=> #<Student id: nil, name: nil, surname: nil, registered_at: nil,
class: nil>
>> roby.name = "roby"
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.generated_methods

Ottengo errore anche facendo
>> r = Student.new :name=>"roby"
NoMethodError: You have a nil object when you didn't expect it!

Sinceramente non lo capisco. Altre volte l'ho fatto senza problemi.
Forse qualcosa mi sfugge.

Ciao e grazie
Antonio C. (Guest)
on 2009-03-30 19:03
(Received via mailing list)
2009/3/30 Roberto C. <removed_email_address@domain.invalid>:
> );
Non chiamare un campo class. Confondi ActiveRecord.

Ciao,
Antonio
--
http://antoniocangiano.com - Zen and the Art of Programming
http://math-blog.com - Mathematics is wonderful!
http://stacktrace.it - Aperiodico di resistenza informatica
Follow me on Twitter: http://twitter.com/acangiano
Author of "Ruby on Rails for Microsoft Developers" (Wrox, 2009)
Roberto C. (Guest)
on 2009-03-30 19:14
Antonio C. wrote:
> 2009/3/30 Roberto C. <removed_email_address@domain.invalid>:
>> );
> Non chiamare un campo class. Confondi ActiveRecord.
>
> Ciao,
> Antonio
> --
> http://antoniocangiano.com - Zen and the Art of Programming
> http://math-blog.com - Mathematics is wonderful!
> http://stacktrace.it - Aperiodico di resistenza informatica
> Follow me on Twitter: http://twitter.com/acangiano
> Author of "Ruby on Rails for Microsoft Developers" (Wrox, 2009)

Grazie!

Non ci avevo pensato.
This topic is locked and can not be replied to.