Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## With this code instead of passing a file and being a file object in the params like:
- ## Parameters: {"commit"=>"Save changes", "authenticity_token"=>"CNHWuiMsSkwK4x3biFGogUnRU2kutvKuCfOTH2Y+PO4=", "painting"=>{"image"=>#<File:/tmp/RackMultipart20100102-3131-9c0z0-0>}}
- ## it passes just a name of the file like so:
- ## Parameters: {"action"=>"create", "authenticity_token"=>"atvaDTdf2yhQKea8t/VBhYyT2ENyK9B/ZYGQSRq9414=", "painting"=>{"title"=>"g", "height"=>"1", "picture"=>"Tweetie.gif", "width"=>"1"}, "controller"=>"admin/paintings"}
- ## Model
- class Painting < ActiveRecord::Base
- has_attached_file :picture
- validates_presence_of :title, :height, :width
- validates_attachment_presence :picture
- end
- ## Controller
- class Admin::PaintingsController < AdminController
- def new
- @painting = Painting.new
- end
- def create
- @painting = Painting.new(params[:painting])
- if @painting.save
- redirect_to admin_paintings_path
- else
- render :new
- end
- end
- end
- ## View
- - content_for :heading do
- %h2.head= "Add Painting"
- - form_for @painting, :url => admin_paintings_path, :html => { :mulitpart => true } do |f|
- = f.error_messages
- %fieldset
- .input_field
- = f.label :title
- = f.text_field :title, :class => "input mediumfield"
- .input_field
- = f.label :height
- = f.text_field :height, :class => "input smallfield"
- %span (mm)
- .input_field
- = f.label :width
- = f.text_field :width, :class => "input smallfield"
- %span (mm)
- .input_field
- = f.label :picture
- = f.file_field :picture
- %input{ :value => "Submit", :class => "submit", :type => "submit"}
- %div{ :class => "clear"}
Add Comment
Please, Sign In to add comment