|
[Rails] Re: Form not working...: msg#03258RubyonRailsTalk
2009/7/31 Craig White <craigwhite@xxxxxxxxxxx>: > > On Fri, 2009-07-31 at 07:46 -0700, Gabriel Bianconi wrote: >> Hello. I created a form and it always throw the 'Title can't be blank' >> error, even if I filled it. >> >> What is wrong? >> >> Thanks, >> >> Gabriel. >> >> ---------------------------- >> >> # new.html.erb >> <h1>Welcome</h1> >> >> <% form_for(@sfile) do |f| %> >> Â <%= f.error_messages %> >> >> Â <p> >> Â Â <%= f.label :title %><br /> >> Â Â <%= f.text_field :title %> >> Â </p> >> Â <p> >> Â Â <%= f.label :description %><br /> >> Â Â <%= f.text_area :description %> >> Â </p> >> Â <p> >> Â Â <%= f.submit 'Create' %> >> Â </p> >> <% end %> >> >> ---- >> >> # sfile.rb >> class Sfile < ActiveRecord::Base >> Â Â Â Âvalidates_presence_of :title >> end >> >> >> --- >> >> # sfiles_controller.rb >> class SfilesController < ApplicationController >> Â Â Â Âdef new >> Â Â Â Â Â Â Â Â@sfile = Sfile.new >> Â Â Â Âend >> >> Â Â Â Âdef create >> Â Â Â Â Â Â Â Â@sfile = Sfile.new(params[:product]) Should this be params[:sfile]? I am not sure where product comes in. Have a look in the log file (log/development.log) to see what parameters are being posted. >> Â Â Â Â Â Â Â Ârespond_to do |format| >> Â Â Â Â Â Â Â Â Â Â Â Âif @sfile.save >> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âflash[:notice] = 'File was successfully >> created.' >> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âformat.html { redirect_to(@sfile) } >> Â Â Â Â Â Â Â Â Â Â Â Âelse >> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âformat.html { render :action => "new" } >> Â Â Â Â Â Â Â Â Â Â Â Âend >> Â Â Â Â Â Â Â Âend >> Â Â Â Âend >> >> Â Â Â Âdef show >> Â Â Â Â Â Â Â Â@sfile = Sfile.find(params[:id]) >> Â Â Â Âend >> end > ---- > try... > > <% form_for(@sfile) do |f| %> > Â<%= f.error_messages %> > > Â<p> > Â Â<%= f.label :title %><br /> > Â Â<%= f.text_field :product, :title %> I think the OP had this bit correct as it is f.text_field not just text_field Colin > Â</p> > Â<p> > Â Â<%= f.label :description %><br /> > Â Â<%= f.text_area :product, :description %> > Â</p> > Â<p> > Â Â<%= f.submit 'Create' %> > Â</p> > <% 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@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |