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]) 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
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]) > 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 %> </p> <p> <%= f.label :description %><br /> <%= f.text_area :product, :description %> </p> <p> <%= f.submit ''Create'' %> </p> <% end %> Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On Jul 31, 2009, at 10:59 AM, Craig White wrote:> 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])You didn''t fix :product on this line to be :sfile. Take a look at the source that your form has generated and you should see the title field has a name like: "sfile[title]">> 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 %> > </p> > <p> > <%= f.label :description %><br /> > <%= f.text_area :product, :description %> > </p> > <p> > <%= f.submit ''Create'' %> > </p> > <% end %> > > Craig > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > > >Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org +1 513-295-4739 Skype: rob.biedenharn
It doesn''t work... I get this: NoMethodError in Sfiles#new Showing app/views/sfiles/new.html.erb where line #8 raised: undefined method `merge'' for :title:Symbol Extracted source (around line #8): 5: 6: <p> 7: <%= f.label :title %><br /> 8: <%= f.text_field :product, :title %> 9: </p> 10: <p> 11: <%= f.label :description %><br /> On 31 jul, 11:59, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> 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]) > > 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 %> > </p> > <p> > <%= f.label :description %><br /> > <%= f.text_area :product, :description %> > </p> > <p> > <%= f.submit ''Create'' %> > </p> > <% end %> > > Craig > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean.
2009/7/31 Craig White <craigwhite-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org>:> > 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 %> >
Rob, I still get the same error... NoMethodError in Sfiles#new Showing app/views/sfiles/new.html.erb where line #8 raised: undefined method `merge'' for :title:Symbol Extracted source (around line #8): 5: 6: <p> 7: <%= f.label :title %><br /> 8: <%= f.text_field :sfile, :title %> 9: </p> 10: <p> 11: <%= f.label :description %><br /> On 31 jul, 12:04, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jul 31, 2009, at 10:59 AM, Craig White wrote: > > > > > 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]) > > You didn''t fix :product on this line to be :sfile. Take a look at the > source that your form has generated and you should see the title field > has a name like: "sfile[title]" > > > > >> 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 %> > > </p> > > <p> > > <%= f.label :description %><br /> > > <%= f.text_area :product, :description %> > > </p> > > <p> > > <%= f.submit ''Create'' %> > > </p> > > <% end %> > > > Craig > > > -- > > This message has been scanned for viruses and > > dangerous content by MailScanner, and is > > believed to be clean. > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > +1 513-295-4739 > Skype: rob.biedenharn
Changing back to my original code, i get this in the log: [4;36;1mSQL (0.0ms) [0m [0;1mSET NAMES ''utf8'' [0m [4;35;1mSQL (0.0ms) [0m [0mSET SQL_AUTO_IS_NULL=0 [0m Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 12:12:26) [POST] Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"Test Title", "description"=>""}} [4;36;1mSfile Columns (0.0ms) [0m [0;1mSHOW FIELDS FROM `sfiles` [0m [4;35;1mSQL (0.0ms) [0m [0mBEGIN [0m [4;36;1mSQL (0.0ms) [0m [0;1mROLLBACK [0m Rendering sfiles/new Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] [4;35;1mSQL (0.0ms) [0m [0mSET NAMES ''utf8'' [0m [4;36;1mSQL (0.0ms) [0m [0;1mSET SQL_AUTO_IS_NULL=0 [0m Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 12:12:31) [POST] Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"", "description"=>""}} [4;35;1mSfile Columns (0.0ms) [0m [0mSHOW FIELDS FROM `sfiles` [0m [4;36;1mSQL (0.0ms) [0m [0;1mBEGIN [0m [4;35;1mSQL (0.0ms) [0m [0mROLLBACK [0m Rendering sfiles/new Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] On 31 jul, 12:07, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/7/31 Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org>: > > > > > > > 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 %>
2009/7/31 Gabriel Bianconi <bianconi.gabriel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Changing back to my original code, i get this in the log: > > [4;36;1mSQL (0.0ms) [0m [0;1mSET NAMES ''utf8'' [0m > [4;35;1mSQL (0.0ms) [0m [0mSET SQL_AUTO_IS_NULL=0 [0m > > > Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 > 12:12:26) [POST] > Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ > xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"Test > Title", "description"=>""}}As you can see the parameters are being sent back as sfile which is what you would expect, so as I and Rob suggested it should be @sfile = Sfile.new(params[:sfile]). Why have you got :product? Colin> > 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.> [4;36;1mSfile Columns (0.0ms) [0m [0;1mSHOW FIELDS FROM `sfiles` > [0m > [4;35;1mSQL (0.0ms) [0m [0mBEGIN [0m > [4;36;1mSQL (0.0ms) [0m [0;1mROLLBACK [0m > Rendering sfiles/new > Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] > [4;35;1mSQL (0.0ms) [0m [0mSET NAMES ''utf8'' [0m > [4;36;1mSQL (0.0ms) [0m [0;1mSET SQL_AUTO_IS_NULL=0 [0m > > > Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 > 12:12:31) [POST] > Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ > xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"", > "description"=>""}} > [4;35;1mSfile Columns (0.0ms) [0m [0mSHOW FIELDS FROM `sfiles` > [0m > [4;36;1mSQL (0.0ms) [0m [0;1mBEGIN [0m > [4;35;1mSQL (0.0ms) [0m [0mROLLBACK [0m > Rendering sfiles/new > Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] > > > On 31 jul, 12:07, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/7/31 Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org>: >> >> >> >> >> >> > 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 %> > > >
It''s working! Thank you very much... I used :product because I saw that in a tutorial. I ''m new with rails. Thanks again. On 31 jul, 12:17, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/7/31 Gabriel Bianconi <bianconi.gabr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Changing back to my original code, i get this in the log: > > > [4;36;1mSQL (0.0ms) [0m [0;1mSET NAMES ''utf8'' [0m > > [4;35;1mSQL (0.0ms) [0m [0mSET SQL_AUTO_IS_NULL=0 [0m > > > Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 > > 12:12:26) [POST] > > Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ > > xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"Test > > Title", "description"=>""}} > > As you can see the parameters are being sent back as sfile which is > what you would expect, so as I and Rob suggested it should be @sfile > = Sfile.new(params[:sfile]). Why have you got :product? > > Colin > > > > > 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. > > [4;36;1mSfile Columns (0.0ms) [0m [0;1mSHOW FIELDS FROM `sfiles` > > [0m > > [4;35;1mSQL (0.0ms) [0m [0mBEGIN [0m > > [4;36;1mSQL (0.0ms) [0m [0;1mROLLBACK [0m > > Rendering sfiles/new > > Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] > > [4;35;1mSQL (0.0ms) [0m [0mSET NAMES ''utf8'' [0m > > [4;36;1mSQL (0.0ms) [0m [0;1mSET SQL_AUTO_IS_NULL=0 [0m > > > Processing SfilesController#create (for 127.0.0.1 at 2009-07-31 > > 12:12:31) [POST] > > Parameters: {"commit"=>"Create", "authenticity_token"=>"cS/ > > xZND8RchwVPTwbGcE7HJe5ZndhyutqCVycX20vBQ=", "sfile"=>{"title"=>"", > > "description"=>""}} > > [4;35;1mSfile Columns (0.0ms) [0m [0mSHOW FIELDS FROM `sfiles` > > [0m > > [4;36;1mSQL (0.0ms) [0m [0;1mBEGIN [0m > > [4;35;1mSQL (0.0ms) [0m [0mROLLBACK [0m > > Rendering sfiles/new > > Completed in 15ms (View: 0, DB: 0) | 200 OK [http://localhost/sfiles] > > > On 31 jul, 12:07, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 2009/7/31 Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org>: > > >> > 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 %>
I''m going back to your original message. The answer that you got from Craig had you changing the view, but ALL that you needed to do was fix the line in the create action to replace :product with :sfile (since the class of the object in the form is Sfile) -Rob On Jul 31, 2009, at 10:46 AM, 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. > > ---------------------------- >This is what your view should look like:> # 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])Just change this line to: @sfile = Sfile.new(params[:sfile])> 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 > endRob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
Gabriel Bianconi wrote:> It''s working! Thank you very much... > > I used :product because I saw that in a tutorial.That response tells me that you have to slow down and think about what you''re doing, not just type in code because you saw it somewhere else... You''re talking about "sfiles" and the tutorial you saw is talking about "products"... why would you expect their code to work in your app? Find a good tutorial, or a good book (Agile Web Development with Rails springs to mind), and read it for understanding... you know, concepts. Don''t just type in what you see, because all that proves when it works is that you''d make a good code-monkey, typing what you''re told. Perhaps a good place to start would be a new Rails application... In that application directory scaffold up a very basic model.. ruby script/generate scaffold person first_name:string last_name:string Now go look through model, the controller, and the views created for you to see how it all fits together. I wouldn''t use scaffold to build a production application, but as an instructional tool for beginners, its great. -- Posted via http://www.ruby-forum.com/.
Thanks for the instructions.... I''ll try to buy that book... On 31 jul, 14:08, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gabriel Bianconi wrote: > > It''s working! Thank you very much... > > > I used :product because I saw that in a tutorial. > > That response tells me that you have to slow down and think about what > you''re doing, not just type in code because you saw it somewhere else... > > You''re talking about "sfiles" and the tutorial you saw is talking about > "products"... why would you expect their code to work in your app? > > Find a good tutorial, or a good book (Agile Web Development with Rails > springs to mind), and read it for understanding... you know, concepts. > > Don''t just type in what you see, because all that proves when it works > is that you''d make a good code-monkey, typing what you''re told. > > Perhaps a good place to start would be a new Rails application... > In that application directory scaffold up a very basic model.. > > ruby script/generate scaffold person first_name:string last_name:string > > Now go look through model, the controller, and the views created for you > to see how it all fits together. I wouldn''t use scaffold to build a > production application, but as an instructional tool for beginners, its > great. > > -- > Posted viahttp://www.ruby-forum.com/.
2009/7/31 Gabriel Bianconi <bianconi.gabriel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Thanks for the instructions.... I''ll try to buy that book...Make sure you get the third edition. Also the online ruby on rails guides are very good, as are the railscasts. Google will find them. Colin> > On 31 jul, 14:08, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> Gabriel Bianconi wrote: >> > It''s working! Thank you very much... >> >> > I used :product because I saw that in a tutorial. >> >> That response tells me that you have to slow down and think about what >> you''re doing, not just type in code because you saw it somewhere else... >> >> You''re talking about "sfiles" and the tutorial you saw is talking about >> "products"... why would you expect their code to work in your app? >> >> Find a good tutorial, or a good book (Agile Web Development with Rails >> springs to mind), and read it for understanding... you know, concepts. >> >> Don''t just type in what you see, because all that proves when it works >> is that you''d make a good code-monkey, typing what you''re told. >> >> Perhaps a good place to start would be a new Rails application... >> In that application directory scaffold up a very basic model.. >> >> ruby script/generate scaffold person first_name:string last_name:string >> >> Now go look through model, the controller, and the views created for you >> to see how it all fits together. I wouldn''t use scaffold to build a >> production application, but as an instructional tool for beginners, its >> great. >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > >
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=UTF-8" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Just another "cut and paste" effect...<br> I agree about "Agile Development with Rails" is a great book....<br> ...but you shoud not cut all of the examples in it...and paste them to your application...<br> <br> <br> Ar Chron escribió: <blockquote cite="mid:51acb569a41665dea4b4c3f07c6f6951-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org" type="cite"> <pre wrap="">Gabriel Bianconi wrote: </pre> <blockquote type="cite"> <pre wrap="">It''s working! Thank you very much... I used :product because I saw that in a tutorial. </pre> </blockquote> <pre wrap=""><!----> That response tells me that you have to slow down and think about what you''re doing, not just type in code because you saw it somewhere else... You''re talking about "sfiles" and the tutorial you saw is talking about "products"... why would you expect their code to work in your app? Find a good tutorial, or a good book (Agile Web Development with Rails springs to mind), and read it for understanding... you know, concepts. Don''t just type in what you see, because all that proves when it works is that you''d make a good code-monkey, typing what you''re told. Perhaps a good place to start would be a new Rails application... In that application directory scaffold up a very basic model.. ruby script/generate scaffold person first_name:string last_name:string Now go look through model, the controller, and the views created for you to see how it all fits together. I wouldn''t use scaffold to build a production application, but as an instructional tool for beginners, its great. </pre> </blockquote> <br> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. <br> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en<br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>