Hello everyone!
I have a form where we can attach files to a post.
But I want to do different things depending wether a file is attached or
not.
So my question is : it it possible to know if a file is attached? I
would say yes, we just need to see if the parameter "file" is empty.
Here are my parameters :
{
"commit"=>"Create",
"post"=>{"title"=>"Test",
"subject"=>"desc test",
"post_attachment"=>
  {
  "post_id"=>"",
  "file"=>"",  # <----------- This is the line with
the file
  "creator_user_id"=>""
  }
}
How can I test if the variable "file" is empty or not?
Thank you!
-- 
Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> How can I test if the variable "file" is empty or not? > Thank you!Answer should be somewhere here: http://www.tutorialspoint.com/ruby/ruby_methods.htm --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 22, 9:08 pm, Guillaume Loader <rails-mailing-l...@andreas- s.net> wrote:> Hello everyone! > > I have a form where we can attach files to a post. > But I want to do different things depending wether a file is attached or > not. > > So my question is : it it possible to know if a file is attached? I > would say yes, we just need to see if the parameter "file" is empty. > > Here are my parameters : > { > "commit"=>"Create", > "post"=>{"title"=>"Test", > "subject"=>"desc test", > "post_attachment"=> > { > "post_id"=>"", > "file"=>"", # <----------- This is the line with the file > "creator_user_id"=>"" > } > > } > > How can I test if the variable "file" is empty or not?Assuming Rails 2.2 or higher: if params[:post_attachment][:file].present? # do file upload here end If Rails 2.1 or earlier, unless params[:post_attachment][:file].blank? # do file upload here end Does this help? Jeff purpleworkshops.com switchingtorails.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Perfect it works! Thank you! -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---