Abder-Rahman Ali
2010-Sep-20 19:39 UTC
unless params[:photo][''photo''].content_type =~ /^image/
In the "Rails cookbook", I read the following statement: unless params[:photo][''photo''].content_type =~ /^image/ What do those parts mean? * params[:photo][''photo'']? * =~ /^image/ Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Sep-20 19:43 UTC
Re: unless params[:photo][''photo''].content_type =~ /^image/
On Mon, Sep 20, 2010 at 2:39 PM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In the "Rails cookbook", I read the following statement: > > unless params[:photo][''photo''].content_type =~ /^image/ > > What do those parts mean?It means you need to learn Ruby.> * params[:photo][''photo'']?params is a hash. :photo is a key in the params hash.> * =~ /^image/=~ means match, as in regular expression matching. /^image/ is a regular expression, it means "starts with ''image''". -- Greg Donald destiney.com | gregdonald.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali
2010-Sep-20 19:48 UTC
Re: unless params[:photo][''photo''].content_type =~ /^image/
Thanks for your reply @Greg. Regarding this part: params[:photo][''photo''] What is [''photo'']? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Sep-20 19:52 UTC
Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
On Mon, Sep 20, 2010 at 2:48 PM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Regarding this part: params[:photo][''photo''] > > What is [''photo'']?It''s probably from a file field: <input type="file" name="photo[photo]" /> -- Greg Donald destiney.com | gregdonald.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali
2010-Sep-20 19:56 UTC
Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
Greg Donald wrote:> On Mon, Sep 20, 2010 at 2:48 PM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> Regarding this part: params[:photo][''photo''] >> >> What is [''photo'']? > > It''s probably from a file field: > > <input type="file" name="photo[photo]" /> > > > > -- > Greg Donald > destiney.com | gregdonald.com"photo" is originally a column field, but what does it mean when inserting it in this shape? params[:photo][''photo''] If params[:photo] is telling us that we have a key :photo, what is the use of [''photo''], this is what I''m not getting. Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Sep-20 20:01 UTC
Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
On Mon, Sep 20, 2010 at 2:56 PM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> "photo" is originally a column field, but what does it mean when > inserting it in this shape? > > params[:photo][''photo''] > > If params[:photo] is telling us that we have a key :photo, what is the > use of [''photo''], this is what I''m not getting.It means there''s another hash inside the params[:photo] hash. params[:photo] <input type="file" name="photo" /> params[:photo][''photo''] <input type="file" name="photo[photo]" /> -- Greg Donald destiney.com | gregdonald.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali
2010-Sep-20 20:07 UTC
Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
I see, thanks a lot. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali
2010-Sep-20 21:11 UTC
Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
Just to make it more clear. When we say: params[:photo] This looks like follows in the "params" table: ------------------ Key | Value ------------------ :photo | "xyz" ------------------ How can this be represented in the params table? params[:photo][''photo''] Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-20 21:12 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
functions that return booleans( true or false), can end with a question mark ( ? ) and in ruby what is called a hash is a list of key value pairs, that is :name => "abder", :id=> ''3'' that is a hash, if i want the value of name , call it like this :name that returns "abder", and hashes can be nested, like this :params=> { :name => "abder", :id=> ''3''} if i cal params directly i get , :name => "abder", :id=> ''3'' but if i want a value that is nested i do params[:name] and it returns "abder" -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-20 21:16 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
> > params[:photo] > > This looks like follows in the "params" table: > > ------------------ > Key | Value > ------------------ > :photo | "xyz" > ------------------ > >not in the table in the params hash , when your app recives info back from the user rails arranges it in a hash called parasm look at you console log when ever you create a resource or dear an specific one you will see parameter => { :id=>1, :name=>"blah" .... } to read from those nested values you call them params[:id] but that is how rails arrenges the request that has nothing to do with the table. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Sep-20 21:17 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
On Mon, Sep 20, 2010 at 4:12 PM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> functions that return booleans( true or false), can end with a question mark > ( ? )Any Ruby method name can end in a question mark, returning a boolean is not required. ruby-1.9.2-p0 > def foo?; return 1; end; foo? => 1 -- Greg Donald destiney.com | gregdonald.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-20 21:21 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
@greg inst that llike a convention, like if a method raises an exception the developer can end ti with a bang ( ! ). if a method returns boolean doesnt the developer end it with ? as a convention? is it or not convention? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abder-Rahman Ali
2010-Sep-20 21:42 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
Thanks @radhames. But, still, I cannot get the idea of: params[:photo][''photo''] And how it is represented. Can you clarify on this? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-20 22:56 UTC
Re: Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
dont worry im reading the book right know to see what the code is about , ill reply in a few minutes -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Sep-20 23:07 UTC
Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
Abder-Rahman Ali wrote:> Thanks @radhames. > > But, still, I cannot get the idea of: > > params[:photo][''photo''] > > And how it is represented. > > Can you clarify on this?What part of that syntax don''t you understand? If the square brackets, review Hash syntax in Ruby. If the nesting, read up on what Rails puts in the params hash. Ask if you have further questions.> > Thanks.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
radhames brito
2010-Sep-20 23:10 UTC
Re: Re: Re: Re: Re: unless params[:photo][''photo''].content_type =~ /^image/
dude , that some jurasick code, if from 2007? wow, what the guy is down is checking the myme type<http://www.iana.org/assignments/media-types/>on the create action, today that is done in a validation in the model. params[:photo][''photo''] is something like this parameter => {:item=>{:name=>"blah blah", :description=> " more blah blah"},:photo =>{:photo=>[ bunch of data about the file ] } } at the end in that bunch of that about the file the browser pases the media type, that is somethie the browser does and they can be application <http://www.iana.org/assignments/media-types/application/> audio <http://www.iana.org/assignments/media-types/audio/> example <http://www.iana.org/assignments/media-types/examples/> image <http://www.iana.org/assignments/media-types/image/> message <http://www.iana.org/assignments/media-types/message/> model <http://www.iana.org/assignments/media-types/model/> multipart <http://www.iana.org/assignments/media-types/multipart/> text <http://www.iana.org/assignments/media-types/text/> video <http://www.iana.org/assignments/media-types/video/> plus the images can be jpg or tiff with .content_type =~ /^image/ he is saying grab the media type see if it starts with image, as the browser pases somthing like this image/jpg or image/tiff so with unless params[:photo][''photo''].content_type =~ /^image/ flash[:error] =" that is not an image file " render :action => ''new'' end he is checking from the params hash if the file uploaded has a media type of image. if not render new -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.