Wayne Molina
2008-Oct-21 23:35 UTC
I don''t get why my model isn''t saving - assistance requested
I''m trying to do something relatively basic. I''m using the restful authentication plugin, so I have Users, and I also have Tasks which belong to a user: class User < ActiveRecord::Base has_many :assigned_tasks, :class_name => "Task", :foreign_key => "assigned_to" has_many :created_tasks, :class_name => "Task", :foreign_key => "created_by" end class Task < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => "created_by" belongs_to :user, :class_name => "User", :foreign_key => "assigned_to" end I''m using Rails 2.1.1 so I''m doing this in the view: # new.html.erb <% form_for @task do |f| %> ... fields <% end %> But the application posts to the index action, not the create action like it''s supposed to; even if I try to post a blank form, when errors should be raised, it''s posting without raising any errors whatsoever. The new action in the controller reads like this: def new @task = @current_user.created_tasks.build end and here''s the create action: def create @task = @current_user.created_tasks.build(params[:task]) if @task.save flash[:notice] = "Task was created" redirect_to task_path(@task) else render :action => ''new'' end end Can someone let me know what I''m doing wrong? Should I not be creating the task with build? I thought I was getting pretty decent with the basics of Rails, but I guess not because something this simple is tripping me up. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wayne M
2008-Oct-22 00:26 UTC
Re: I don''t get why my model isn''t saving - assistance requested
Okay... I have no idea what the problem was, but it seems to be working right now. On Oct 21, 7:35 pm, Wayne Molina <wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m trying to do something relatively basic. I''m using the restful > authentication plugin, so I have Users, and I also have Tasks which > belong to a user: > > class User < ActiveRecord::Base > has_many :assigned_tasks, :class_name => "Task", :foreign_key => > "assigned_to" > has_many :created_tasks, :class_name => "Task", :foreign_key => > "created_by" > end > > class Task < ActiveRecord::Base > belongs_to :creator, :class_name => "User", :foreign_key => > "created_by" > belongs_to :user, :class_name => "User", :foreign_key => > "assigned_to" > end > > I''m using Rails 2.1.1 so I''m doing this in the view: > > # new.html.erb > <% form_for @task do |f| %> > ... fields > <% end %> > > But the application posts to the index action, not the create action > like it''s supposed to; even if I try to post a blank form, when errors > should be raised, it''s posting without raising any errors whatsoever. > The new action in the controller reads like this: > > def new > @task = @current_user.created_tasks.build > end > > and here''s the create action: > > def create > @task = @current_user.created_tasks.build(params[:task]) > if @task.save > flash[:notice] = "Task was created" > redirect_to task_path(@task) > else > render :action => ''new'' > end > end > > Can someone let me know what I''m doing wrong? Should I not be > creating the task with build? I thought I was getting pretty decent > with the basics of Rails, but I guess not because something this > simple is tripping me up.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ami
2008-Oct-22 03:16 UTC
Re: I don''t get why my model isn''t saving - assistance requested
if you do task.save! it should show you where it fails On Oct 21, 8:26 pm, Wayne M <wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Okay... I have no idea what the problem was, but it seems to be > working right now. > > On Oct 21, 7:35 pm, Wayne Molina <wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m trying to do something relatively basic. I''m using the restful > > authentication plugin, so I have Users, and I also have Tasks which > > belong to a user: > > > class User < ActiveRecord::Base > > has_many :assigned_tasks, :class_name => "Task", :foreign_key => > > "assigned_to" > > has_many :created_tasks, :class_name => "Task", :foreign_key => > > "created_by" > > end > > > class Task < ActiveRecord::Base > > belongs_to :creator, :class_name => "User", :foreign_key => > > "created_by" > > belongs_to :user, :class_name => "User", :foreign_key => > > "assigned_to" > > end > > > I''m using Rails 2.1.1 so I''m doing this in the view: > > > # new.html.erb > > <% form_for @task do |f| %> > > ... fields > > <% end %> > > > But the application posts to the index action, not the create action > > like it''s supposed to; even if I try to post a blank form, when errors > > should be raised, it''s posting without raising any errors whatsoever. > > The new action in the controller reads like this: > > > def new > > @task = @current_user.created_tasks.build > > end > > > and here''s the create action: > > > def create > > @task = @current_user.created_tasks.build(params[:task]) > > if @task.save > > flash[:notice] = "Task was created" > > redirect_to task_path(@task) > > else > > render :action => ''new'' > > end > > end > > > Can someone let me know what I''m doing wrong? Should I not be > > creating the task with build? I thought I was getting pretty decent > > with the basics of Rails, but I guess not because something this > > simple is tripping me up.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Levente Bagi
2008-Nov-04 20:24 UTC
Re: I don''t get why my model isn''t saving - assistance requested
I had the same problem, restarting the server helped. On okt. 22, 04:16, Ami <Ami.mahl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if you do task.save! it should show you where it fails > > On Oct 21, 8:26 pm, Wayne M <wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Okay... I have no idea what the problem was, but it seems to be > > working right now. > > > On Oct 21, 7:35 pm, Wayne Molina <wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''m trying to do something relatively basic. I''m using the restful > > > authentication plugin, so I have Users, and I also have Tasks which > > > belong to a user: > > > > class User < ActiveRecord::Base > > > has_many :assigned_tasks, :class_name => "Task", :foreign_key => > > > "assigned_to" > > > has_many :created_tasks, :class_name => "Task", :foreign_key => > > > "created_by" > > > end > > > > class Task < ActiveRecord::Base > > > belongs_to :creator, :class_name => "User", :foreign_key => > > > "created_by" > > > belongs_to :user, :class_name => "User", :foreign_key => > > > "assigned_to" > > > end > > > > I''m using Rails 2.1.1 so I''m doing this in the view: > > > > # new.html.erb > > > <% form_for @task do |f| %> > > > ... fields > > > <% end %> > > > > But the application posts to theindexaction, not thecreateaction > > > like it''s supposed to; even if I try toposta blank form, when errors > > > should be raised, it''s posting without raising any errors whatsoever. > > > The new action in the controller reads like this: > > > > def new > > > @task = @current_user.created_tasks.build > > > end > > > > and here''s thecreateaction: > > > > defcreate > > > @task = @current_user.created_tasks.build(params[:task]) > > > if @task.save > > > flash[:notice] = "Task was created" > > > redirect_to task_path(@task) > > > else > > > render :action => ''new'' > > > end > > > end > > > > Can someone let me know what I''m doing wrong? Should I not be > > > creating the task with build? I thought I was getting pretty decent > > > with the basics of Rails, but I guess not because something this > > > simple is tripping me up.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---