|
[Rails] Re: Form not working...: msg#03255RubyonRailsTalk
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@xxxxxxxxxxxxxxxxxxxxxx +1 513-295-4739 Skype: rob.biedenharn --~--~---------~--~----~------------~-------~--~----~ 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 |