in your create action why do you create the record before validation ?
should not it be ?

  def create
    @project = Project.new(params[:project])
    if @project.save
       flash[ :notice ] = "Projeto criado com sucesso !"
       redirect_to :action => "index"
    else
       render :new
    end
  end



On 17 fév, 19:59, Felipe Pieretti Umpierre <li...@ruby-forum.com>
wrote:
> I'm sorry Dave, I was updated the post, but
>
> I got make it work, but now another error is showing, when I put a
> image, on my file_field the rails add a div error.
>
> I don't know why...
>
> Now I put the image on file field, but when I click on submit, the page
> is reload to my new action, with the error div in the file field.
>
> my controller
>
> class ProjectsController < ApplicationController
>   def index
>     @projects = Project.all
>   end
>
>   def new
>     @project = Project.new
>   end
>
>   def create
>     @project = Project.create( params[ :project ] )
>
>     if @project.valid?
>       flash[ :notice ] = "Projeto criado com sucesso !"
>       redirect_to :action => "index"
>     else
>       render "new"
>     end
>   end
> end
>
> and my action after clicked on submit:
>
> <div class="field_with_errors"><label
> for="project_image">Imagem</label></div>
>         <div class="field_with_errors"><input id="project_image"
> name="project[image]" type="file" /></div><br />
>
> --
> Posted viahttp://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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to