image uploading form working

This commit is contained in:
jywarren
2015-01-07 20:21:32 -05:00
parent 6ba4dd1bc1
commit 0945d55443
9 changed files with 20 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ function addUploadedImageToSidebar($upload) {
jQuery(document).ready(function($) {
$('#fileupload').fileupload({
paramName: 'warpable[uploaded_data]',
paramName: 'uploaded_data',
autoUpload: 'true',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 10000000

View File

@@ -1,4 +1,5 @@
class ApplicationController < ActionController::Base
#include OpenIdAuthentication # shouldn't be necessary!!
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

View File

@@ -3,7 +3,7 @@ require 'open3'
class MapsController < ApplicationController
protect_from_forgery :except => [:export]
before_filter :require_user, :only => [:create, :new, :edit, :update, :destroy]
before_filter :require_login, :only => [:create, :new, :edit, :update, :destroy]
layout 'knitter2'

View File

@@ -2,7 +2,6 @@ require 'uri'
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
include OpenIdAuthentication # shouldn't be necessary!!
#protect_from_forgery :except => [:create]
@@openid_url_base = "http://publiclab.org/people/"

View File

@@ -28,9 +28,9 @@ class WarpablesController < ApplicationController
end
def create
@warpable = Warpable.new(params[:warpable])
@warpable = Warpable.new
@warpable.image = params[:uploaded_data]
@warpable.map_id = params[:map_id]
print params[:map_id]
map = Map.find(params[:map_id])
map.updated_at = Time.now
map.save
@@ -40,7 +40,7 @@ class WarpablesController < ApplicationController
render :json => [@warpable.fup_json].to_json,
:content_type => 'text/html'
}
format.json { render :json => {:files => [@warpable.fup_json]}, :status => :created, :location => @warpable.public_filename() }
format.json { render :json => {:files => [@warpable.fup_json]}, :status => :created, :location => @warpable.image.url }
else
format.html { render :action => "new" }
format.json { render :json => {:files => [@warpable.fup_error_json]}, :layout => false}

View File

@@ -1,5 +1,6 @@
require 'open3'
class Map < ActiveRecord::Base
attr_accessible :author, :name, :lat, :lon, :location, :description
before_validation :update_name
validates_presence_of :name,:author,:lat,:lon
validates_uniqueness_of :name
@@ -30,6 +31,7 @@ class Map < ActiveRecord::Base
end
end
# impose URL-safe sanity on name
def validate
self.name != 'untitled'
self.name = self.name.gsub(' ','-').gsub('_','-').downcase
@@ -41,6 +43,7 @@ class Map < ActiveRecord::Base
self.password = Password::update(self.password) if self.password != ""
end
# this might have been for a migration; grep for it
def update_name
self.name = self.name.gsub(/\W/, '-').downcase
end

View File

@@ -21,18 +21,18 @@ class Warpable < ActiveRecord::Base
#Json formatting for file upload plugin
def fup_json
{"name" => read_attribute(:filename),
"size" => read_attribute(:size),
"url" => self.public_filename(:medium),
{"name" => read_attribute(:image_filename),
"size" => read_attribute(:image_size),
"url" => self.image.url(:medium),
"id" => self.read_attribute(:id),
"thumbnail_url" => self.public_filename(:thumb),
"delete_url" => public_filename(self),
"thumbnail_url" => self.image.url(:thumb),
"delete_url" => self.image.url,
"delete_type" => "DELETE"}
end
def fup_error_json
{"name" => read_attribute(:filename),
"size" => read_attribute(:size),
{"name" => read_attribute(:image_filename),
"size" => read_attribute(:image_size),
"error" => self.errors["base"]}
end

View File

@@ -24,11 +24,11 @@
<% @maps.each do |map| %>
<div class="map col-md-3 <%= 'odd' if odd %>">
<% if !map.private && map.warpables.length > 0 %>
<a href="/maps/<%= map.id %>">
<a href="/map/<%= map.id %>">
<img src="<%= map.warpables.first.image.url(:small) %>" />
</a>
<% end %>
<h3><%= link_to map.name.capitalize, map %></a></h3>
<h3><a href="/map/<%= map.id %>"><%= map.name.capitalize %></a></h3>
<p>
<small>by <a href="/profile/<%= map.author %>"><%= map.author %></a> | <%= map.location %></small></p>
<p class="description"><small>

View File

@@ -10,7 +10,7 @@
</div>
<div class="modal-body">
<div>
<% form_for [@map, Warpable.new], :html => { :multipart => true, :id => "fileupload" } do |f| %>
<%= form_for [@map, Warpable.new], :html => { :multipart => true, :id => "fileupload" } do |f| %>
<input id="warpable_map_id" name="map_id" type="hidden" value="<%= @map_id %>" />
<div class="row">