On 21 June 2011 13:31, Jen <jen.bot...@gmail.com> wrote: > Hi, > I am writing some simple upload functionality for an application. I can't > figure out how to check if file@field is empty. Currently I am trying to use > an if statement, so the post action will only occure if 'upload' is not nil. > I have also tried using the .blank method with no success. > > Any advice would be great. > Thanks in advance, > Jen. > > If statement: > #posts to the data model. > if !:upload.nil?
Are you trying to check whether param[:upload] has a value? Is so then you can use if !params[:upload].blank? blank? returns true for nil or an empty string. nil? returns true for nil but false for empty string. Colin > post = Upload.save(params[:upload]) > puts "file uploaded" > render 'upload' > repo.commit_all('params[:message]') > else > redirect_to 'upload' > 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@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. > > -- 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.