Hello, I am fairly new to rails, and I keep having an error in my migrations, cant mass assign protected attributes... it does not show what attribute is mass assigned, just shows the file that has the problem... here is the file any help would be greatly appreciated!! class Subjects < ActiveRecord::Migration def self.up create_table :subjects do |t| t.column :name, :string end Subject.create :name => "Physics" Subject.create :name => "Mathematics" Subject.create :name => "Chemistry" Subject.create :name => "Psychology" Subject.create :name => "Geography" end def self.down drop_table :subjects end end Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/03d2715c-5a4c-48e7-a0d6-c07b380f5a55%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
try add `Project.reset_column_information` before Subject.create On Mon, Jun 17, 2013 at 11:36 AM, Clay McCullough <clay44-mqiTH3uDUMEAvxtiuMwx3w@public.gmane.org> wrote:> Hello, I am fairly new to rails, and I keep having an error in my > migrations, cant mass assign protected attributes... it does not show what > attribute is mass assigned, just shows the file that has the problem... > here is the file any help would be greatly appreciated!! > > class Subjects < ActiveRecord::Migration > def self.up > create_table :subjects do |t| > t.column :name, :string > end > Subject.create :name => "Physics" > Subject.create :name => "Mathematics" > Subject.create :name => "Chemistry" > Subject.create :name => "Psychology" > Subject.create :name => "Geography" > end > > def self.down > drop_table :subjects > end > end > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/03d2715c-5a4c-48e7-a0d6-c07b380f5a55%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAO1cLnzfGcyxjmJu3CPN5eL7_xNfy7ET%3DVTbfgmJnzRMbWNkCg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On 17 June 2013 06:31, William Herry <WilliamHerryChina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try add `Project.reset_column_information` before Subject.createOr even Subject.reset_column_information Colin> > > On Mon, Jun 17, 2013 at 11:36 AM, Clay McCullough <clay44-mqiTH3uDUMEAvxtiuMwx3w@public.gmane.org> wrote: >> >> Hello, I am fairly new to rails, and I keep having an error in my >> migrations, cant mass assign protected attributes... it does not show what >> attribute is mass assigned, just shows the file that has the problem... here >> is the file any help would be greatly appreciated!! >> >> class Subjects < ActiveRecord::Migration >> def self.up >> create_table :subjects do |t| >> t.column :name, :string >> end >> Subject.create :name => "Physics" >> Subject.create :name => "Mathematics" >> Subject.create :name => "Chemistry" >> Subject.create :name => "Psychology" >> Subject.create :name => "Geography" >> end >> >> def self.down >> drop_table :subjects >> end >> end >> >> Thanks! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/03d2715c-5a4c-48e7-a0d6-c07b380f5a55%40googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CAO1cLnzfGcyxjmJu3CPN5eL7_xNfy7ET%3DVTbfgmJnzRMbWNkCg%40mail.gmail.com. > > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsPtgq%2B9LLeX-x5VdvN1uHUfKY82kxfQVDGrsDHzsPdRw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
You should add attr_accessible :name in model. In latest version of rails all the attributes of model are bt default protected. On Monday, June 17, 2013 9:06:57 AM UTC+5:30, Clay McCullough wrote:> > Hello, I am fairly new to rails, and I keep having an error in my > migrations, cant mass assign protected attributes... it does not show what > attribute is mass assigned, just shows the file that has the problem... > here is the file any help would be greatly appreciated!! > > class Subjects < ActiveRecord::Migration > def self.up > create_table :subjects do |t| > t.column :name, :string > end > Subject.create :name => "Physics" > Subject.create :name => "Mathematics" > Subject.create :name => "Chemistry" > Subject.create :name => "Psychology" > Subject.create :name => "Geography" > end > > def self.down > drop_table :subjects > end > end > > Thanks! >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/341c8959-ec37-45b4-8634-00ba6cec3a3d%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Don''t use migrations to set data, use seeds for that if you must. Using migrations can lead to inabilities to rollback if need be. The exceptions to this are cases where model relationships or default values need to be set to have the application work. Your example is not such a case. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/51bfd69c.6929320a.10fc.5090%40mx.google.com. For more options, visit https://groups.google.com/groups/opt_out.