Guest User

Untitled

a guest
Jan 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. # POST /photos
  2. # POST /photos.json
  3. def create
  4.  
  5. @photo = Photo.new(params[:photo])
  6. @photo.lat = params["photo%5Blat%5D"].to_s
  7. @photo.lng = params["photo%5Blng%5D"].to_s
  8. @photo.description = params[:description]
  9. @photo.takenby = params[:takenby].to_s
  10.  
  11. @photo.save
  12.  
  13. puts "photos/create photos.inspect= #{@photo.inspect}"
  14.  
  15.  
  16.  
  17. end
  18.  
  19. class Photo < ActiveRecord::Base
  20.  
  21.  
  22. attr_accessible :lat, :lng, :image
  23. vendor = params[:description]
  24. owner = params[:owner]
  25. Paperclip.interpolates :prefix do |attachment, style|
  26. "#{owner}/#{Date.today.to_s }/#{vendor}"
  27. end
  28.  
  29.  
  30. has_attached_file :image,
  31. :path => ":prefix/:basename.:extension",
  32. :styles => { :thumbnail => "57x57", :original => "100x100" },
  33. :storage => :s3,
  34. :s3_credentials => S3_CREDENTIALS
  35.  
  36. Started GET "/photos?lat=37.785834&lng=-122.406417" for 127.0.0.1 at 2012-09-26
  37. 21:08:57 -0700
  38. 21:08:57 web.1 | Processing by PhotosController#index as JSON
  39. 21:08:57 web.1 | Parameters: {"lat"=>"37.785834", "lng"=>"-122.406417"}
  40. 21:08:57 web.1 | Completed 500 Internal Server Error in 4ms
  41. 21:08:57 web.1 | NameError (undefined local variable or method `params' for #<Class:0x007fb7d4fa3320>):
  42. 21:08:57 web.1 | app/models/photo.rb:23:in `<class:Photo>'
  43. 21:08:57 web.1 | app/models/photo.rb:18:in `<top (required)>'
  44. 21:08:57 web.1 | app/controllers/photos_controller.rb:14:in `index'
  45.  
  46. photo.rb
  47.  
  48. Paperclip.interpolates :prefix do |attachment, style|
  49. "#{attachment.instance.takenby}/#{Date.today.to_s }/#{attachment.instance.description}"
  50. end
  51.  
  52. vendor = params[:description]
  53. owner = params[:owner]
  54.  
  55. Paperclip.interpolates :description do |attachment, style|
  56. attachment.instance.description # or other attribute
  57. end
  58.  
  59. has_attached_file :image,
  60. :path => ":description/:basename.:extension",
  61. :styles => { :thumbnail => "57x57", :original => "100x100" },
  62. :storage => :s3,
  63. :s3_credentials => S3_CREDENTIALS
  64.  
  65. obj.set_values(params)
  66.  
  67. def set_values(params)
  68. self.vendor = params[:description]
  69. self.owner = params[:owner]
  70. end
  71.  
  72. <%= form_for (@post) do |f| %>
  73.  
  74. <%= form_for @post, :html => { :multipart => true } do |f| %>
  75.  
  76. <p>
  77. <%= f.file_field :photo %>
  78. </p>
Add Comment
Please, Sign In to add comment