Hi folks, I''m new to RoR and getting stuck on something that should be quite simple. I''m just playing with a simple Blog concept, and working on the "create" view and action. Here are snippets the controller and view: =================== def create @post = Post.new(params[:post]) if request.post? @post.save redirect_to :action=>''index'' end end ================== ==================<% form_for :post do |f| %> <p> Title:<br/> <%= f.text_field :title %> </p> <p> Content:<br/> <%= f.text_field :content %> </p> <% end %> <%= submit_tag %> ================== I have probably missed something simple and fundamental but can''t for the life of me see it. The create controller is not saving or redirecting to the index page. Please let me know if I need to post more code. Any help or suggestions would be greatly appreciated. Thanks, Dany. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try putting the submit_tag within the form_for block: <% form_for :post do |f| %> <p> Title:<br/> <%= f.text_field :title %> </p> <p> Content:<br/> <%= f.text_field :content %> </p> <%= submit_tag %> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe you need <% form_for(:post, :url => posts_path) do |f| %> Check your development.log to make sure that your params are getting posted to the create method. Also look for errors there. I''m not sure but rails may not like the name post for your model. On Oct 18, 3:22 pm, Dany Wu <dany...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks, > > I''m new to RoR and getting stuck on something that should be quite > simple. I''m just playing with a simple Blog concept, and working on > the "create" view and action. Here are snippets the controller and > view: > > ===================> def create > @post = Post.new(params[:post]) > if request.post? > @post.save > redirect_to :action=>''index'' > end > end > ==================> > ==================> <% form_for :post do |f| %> > <p> > Title:<br/> > <%= f.text_field :title %> > </p> > <p> > Content:<br/> > <%= f.text_field :content %> > </p> > <% end %> > <%= submit_tag %> > ==================> > I have probably missed something simple and fundamental but can''t for > the life of me see it. The create controller is not saving or > redirecting to the index page. Please let me know if I need to post > more code. > > Any help or suggestions would be greatly appreciated. > > Thanks, > Dany.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
also make surre post is the name of the model. And the params you use in the view match the columns in your post table. Tom -----Original Message----- From: "randomutterings..." <randomutterings-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Date: Friday, Oct 19, 2007 3:24 am Subject: [Rails] Re: Newbie question: persisting an object To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>Reply-To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Maybe you need <% form_for(:post, :url => posts_path) do |f| %> Check your development.log to make sure that your params are getting posted to the create method. Also look for errors there. I''m not sure but rails may not like the name post for your model. On Oct 18, 3:22 pm, Dany Wu <dany...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Hi folks,> I''m new to RoR and getting stuck on something that should be quitesimple. I''m just playing with a simple Blog concept, and working on the "create" view and action. Here are snippets the controller and view:> =================== def create@post = Post.new(params[:post]) if request.post? @post.save redirect_to :action=>''index'' end end ==================> ================== <% form_for :post do |f| %><p> Title:<br/> <%= f.text_field :title %> </p> <p> Content:<br/> <%= f.text_field :content %> </p> <% end %> <%= submit_tag %> ==================> I have probably missed something simple and fundamental but can''t forthe life of me see it. The create controller is not saving or redirecting to the index page. Please let me know if I need to post more code.> Any help or suggestions would be greatly appreciated.> Thanks,Dany. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
wtf -- 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-/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 -~----------~----~----~----~------~----~------~--~---
D''oh! Thanks for pointing that out - at some stage, when I was stripping all the fancy presentation bits, the submit_tag got pasted in the wrong place. Thanks for pointing that out! Cheers, Dany. On Oct 20, 2:09 am, Anthony Franco <robinanth...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try putting the submit_tag within the form_for block: > > <% form_for :post do |f| %> > <p> > Title:<br/> > <%= f.text_field :title %> > </p> > <p> > Content:<br/> > <%= f.text_field :content %> > </p> > <%= submit_tag %> > <% end %>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---