-
-
Save radar/267324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 [:admin, @painting], :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"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment