Okay, so this is driving me crazy. I''m trying to do a file upload using code from a book. What happens: I get wrong number of arguments (1 for 0) in the upload controller save action. No idea why. Schema: The schema for the picture model object is just a textfield named comments and a binary field called data. Upload controller: def get @picture =Picture.new end def save @picture=Picture.new(params[:picture]) if @picture.save redirect_to(:action=>''show'', :id=> @picture.id) else render(:action=> :get) end end def picture @picture=Picture.find(params[:id]) send_data(@picture.data, :filename=>@picture.name, :type=>@picture.content_type, :disposition=>"inline") end def show @picture=Picture.find(params[:id]) end Views: For Get-- <h1>Upload Image File</h1> <% form_for(:picture, :url=> {:action=>''save''}, :html=> { :multipart=> true}) do |f| %> <%= f.error_messages %> <p> <%= f.label :comment %><br /> <%= f.text_area :comment %> </p> <p> <%= f.file_field("uploaded_picture")%> </p> <p> <%= f.submit "Create" %> </p> <% end %> Then there''s a show view that''s not really worth including, because it is standard and nowhere near the error. What am I doing wrong? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh and the model code is: class Picture < ActiveRecord::Base validates_format_of :content_type, :with=>/^image/, :message=>''Uploading is limited to pictures'' def uploaded_picture=(picture_field) self.name = base_part_of(picture_field.original_filename) self.content_type = picture_field.content_type.chomp self.data = picture.field.read end def base_part_of File.basename(file_name).gsub(/[^\w._-]/,'''') end end On Jun 14, 9:50 pm, Ron <stecklyena...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Okay, so this is driving me crazy. I''m trying to do a file upload > using code from a book. > > What happens: > I get wrong number of arguments (1 for 0) in the upload controller > save action. No idea why. > > Schema: > The schema for the picture model object is just a textfield named > comments and a binary field called data. > > Upload controller: > > def get > @picture =Picture.new > end > > def save > @picture=Picture.new(params[:picture]) > if @picture.save > redirect_to(:action=>''show'', :id=> @picture.id) > else > render(:action=> :get) > end > end > > def picture > @picture=Picture.find(params[:id]) > send_data(@picture.data, > :filename=>@picture.name, > :type=>@picture.content_type, > :disposition=>"inline") > end > > def show > @picture=Picture.find(params[:id]) > end > > Views: > For Get-- > <h1>Upload Image File</h1> > > <% form_for(:picture, > :url=> {:action=>''save''}, > :html=> { :multipart=> true}) do |f| %> > > <%= f.error_messages %> > > <p> > <%= f.label :comment %><br /> > <%= f.text_area :comment %> > </p> > <p> > > <%= f.file_field("uploaded_picture")%> > </p> > <p> > <%= f.submit "Create" %> > </p> > <% end %> > > Then there''s a show view that''s not really worth including, because it > is standard and nowhere near the error. > > What am I doing wrong? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ron wrote:> Oh and the model code is: > > class Picture < ActiveRecord::Base > validates_format_of :content_type, > :with=>/^image/, > :message=>''Uploading is limited to pictures'' > > def uploaded_picture=(picture_field) > self.name = base_part_of(picture_field.original_filename) > self.content_type = picture_field.content_type.chomp > self.data = picture.field.read > end > > def base_part_of > File.basename(file_name).gsub(/[^\w._-]/,'''') > end > endLooks like this is the problem: self.name = base_part_of(picture_field.original_filename) The function does not accept any arguments. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, So I''m following along with Agile Development with Rails, 2nd edition. I got the code from pg. 503. I''m not saying this because I think its right--I''m just saying it because if it doesn''t take an argument, I''m not sure how else to do it.... Ron On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Oh and the model code is: > > > class Picture < ActiveRecord::Base > > validates_format_of :content_type, > > :with=>/^image/, > > :message=>''Uploading is limited to pictures'' > > > def uploaded_picture=(picture_field) > > self.name = base_part_of(picture_field.original_filename) > > self.content_type = picture_field.content_type.chomp > > self.data = picture.field.read > > end > > > def base_part_of > > File.basename(file_name).gsub(/[^\w._-]/,'''') > > end > > end > > Looks like this is the problem: > self.name = base_part_of(picture_field.original_filename) > > The function does not accept any arguments. > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi, So I''m following along with Agile Development with Rails, 2nd edition. I got the code from pg. 503. I''m not saying this because I think its right--I''m just saying it because if it doesn''t take an argument, I''m not sure how else to do it.... Ron On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Oh and the model code is: > > > class Picture < ActiveRecord::Base > > validates_format_of :content_type, > > :with=>/^image/, > > :message=>''Uploading is limited to pictures'' > > > def uploaded_picture=(picture_field) > > self.name = base_part_of(picture_field.original_filename) > > self.content_type = picture_field.content_type.chomp > > self.data = picture.field.read > > end > > > def base_part_of > > File.basename(file_name).gsub(/[^\w._-]/,'''') > > end > > end > > Looks like this is the problem: > self.name = base_part_of(picture_field.original_filename) > > The function does not accept any arguments. > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Ron wrote:> Hi, > > So I''m following along with Agile Development with Rails, 2nd edition. > > I got the code from pg. 503. I''m not saying this because I think its > right--I''m just saying it because if it doesn''t take an argument, I''m > not sure how else to do it.... > > Ron > > On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>On page 503 the base_part_of function accepts a filename argument. I think someone has had too much coffee :) -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, So I''m following along with Agile Development with Rails, 2nd edition. I got the code from pg. 503. I''m not saying this because I think its right--I''m just saying it because if it doesn''t take an argument, I''m not sure how else to do it.... Ron On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Oh and the model code is: > > > class Picture < ActiveRecord::Base > > validates_format_of :content_type, > > :with=>/^image/, > > :message=>''Uploading is limited to pictures'' > > > def uploaded_picture=(picture_field) > > self.name = base_part_of(picture_field.original_filename) > > self.content_type = picture_field.content_type.chomp > > self.data = picture.field.read > > end > > > def base_part_of > > File.basename(file_name).gsub(/[^\w._-]/,'''') > > end > > end > > Looks like this is the problem: > self.name = base_part_of(picture_field.original_filename) > > The function does not accept any arguments. > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi, So I''m following along with Agile Development with Rails, 2nd edition. I got the code from pg. 503. I''m not saying this because I think its right--I''m just saying it because if it doesn''t take an argument, I''m not sure how else to do it.... Ron On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Oh and the model code is: > > > class Picture < ActiveRecord::Base > > validates_format_of :content_type, > > :with=>/^image/, > > :message=>''Uploading is limited to pictures'' > > > def uploaded_picture=(picture_field) > > self.name = base_part_of(picture_field.original_filename) > > self.content_type = picture_field.content_type.chomp > > self.data = picture.field.read > > end > > > def base_part_of > > File.basename(file_name).gsub(/[^\w._-]/,'''') > > end > > end > > Looks like this is the problem: > self.name = base_part_of(picture_field.original_filename) > > The function does not accept any arguments. > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
I think you could be right about the coffee (although its green tea in my case), Chris. Just as an aside, do you know what disposition inline means under send_data on the upload controller? Thanks for the help! Ron On Jun 14, 10:10 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Hi, > > > So I''m following along with Agile Development with Rails, 2nd edition. > > > I got the code from pg. 503. I''m not saying this because I think its > > right--I''m just saying it because if it doesn''t take an argument, I''m > > not sure how else to do it.... > > > Ron > > > On Jun 14, 10:02 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > On page 503 the base_part_of function accepts a filename argument. > > I think someone has had too much coffee :) > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Ron wrote:> Just as an aside, do you know what disposition > inline means under send_data on the upload controller?The inline option is what allow the image to be rendered on the page rather than downloaded. If instead you set the disposition to "attachment" it should prompt you to save/open the file.> Thanks for the help!Anytime :) -- 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 -~----------~----~----~----~------~----~------~--~---
Ah! That makes sense. So my typo was behind the arguments issue...but now that it uploads it, there is a problem that ''picture'' is an undefined local variable or method in the save action of the upload controller. I''m not sure why because I defined a picture method for in the picture model. Is it an issue of scope? R On Jun 14, 10:32 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ron wrote: > > Just as an aside, do you know what disposition > > inline means under send_data on the upload controller? > > The inline option is what allow the image to be rendered on the page > rather than downloaded. If instead you set the disposition to > "attachment" it should prompt you to save/open the file. > > > Thanks for the help! > > Anytime :) > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Whoops...I''m the world''s worst typist. It turns out that it was just a typo in the model...picture.field instead of picture_field. Really need to drink fewer stimulants... Ron On Jun 14, 10:54 pm, Ron <stecklyena...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ah! That makes sense. > > So my typo was behind the arguments issue...but now that it uploads > it, there is a problem that ''picture'' is an undefined local variable > or method in the save action of the upload controller. I''m not sure > why because I defined a picture method for in the picture model. Is > it an issue of scope? > > R > On Jun 14, 10:32 pm, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Ron wrote: > > > Just as an aside, do you know what disposition > > > inline means under send_data on the upload controller? > > > The inline option is what allow the image to be rendered on the page > > rather than downloaded. If instead you set the disposition to > > "attachment" it should prompt you to save/open the file. > > > > Thanks for the help! > > > Anytime :) > > > -- > > 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-/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 -~----------~----~----~----~------~----~------~--~---