I been working on a screencast pro proposed by Ryan called the Jquery file uploads. However every time i input images it doesn’t get uploaded. I am not sure what i am doing wrong here my code. I am using google and did try to upload it but it doesn’t seem to be doing anything
Javascript
application.js
//= require jquery
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl
//= require_tree .
painting.js.coffee
jQuery ->
$('#new_painting').fileupload
Views
_form.html.erb
<%= form_for @painting, :html => {:multipart => true} do |f| %>
<div class="field">
<%= f.hidden_field :galley_id %>
</div>
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
index.html.erb
Painting Gallery
<%= form_for Painting.new do |f| %>
<%= f.label :image, "Upload paintings:" %>
<%= f.file_field :image, multiple: true, name: "painting[image]" %>
<% end %>
show.html.erb
<p><%= image_tag @painting.image_url %></p>
<p>
<%= link_to "Edit", edit_painting_path(@painting) %> |
<%= link_to "Destroy", @painting, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "Back to Paintings", paintings_path %>
</p>
Controller
def index
@paintings = Painting.all
end
def show
@painting = Painting.find(params[:id])
end
def new
@painting = Painting.new
end
def create
@painting = Painting.create(params[:painting])
end
def edit
@painting = Painting.find(params[:id])
end
def update
@painting = Painting.find(params[:id])
if @painting.update_attributes(params[:painting])
redirect_to paintings_url, notice: "Painting was successfully updated."
else
render :edit
end
end
def destroy
@painting = Painting.find(params[:id])
@painting.destroy
redirect_to paintings_url, notice: "Painting was successfully destroyed."
end
Model
attr_accessible :image
mount_uploader :image, ImageUploader
My main issues is when it comes to upload any picture it just doesn’t have a submit button and not sure how to make it work, did i miss something??
You are likely successfully uploading the file to your controller action, but you’re not doing anythin with it other than
You need to do more, like maybe saving the uploaded file somewhere on the server?
This will extract the uploaded image and write it to the server. Content_type is handy if you want to record the MIME type in the database as well.