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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to