user images
This commit is contained in:
parent
2e44f9ccf3
commit
cacf1879c3
7 changed files with 52 additions and 3 deletions
|
@ -2,8 +2,8 @@ class UserController < ApplicationController
|
|||
layout 'site'
|
||||
|
||||
before_filter :authorize, :only => [:api_details, :api_gpx_files]
|
||||
before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend]
|
||||
before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend]
|
||||
before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image]
|
||||
before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image]
|
||||
|
||||
filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
|
||||
|
||||
|
@ -155,6 +155,12 @@ class UserController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def upload_image
|
||||
@user.image = params[:user][:image]
|
||||
@user.save!
|
||||
redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
|
||||
end
|
||||
|
||||
def api_details
|
||||
render :text => @user.to_xml.to_s, :content_type => "text/xml"
|
||||
end
|
||||
|
|
|
@ -25,6 +25,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
before_save :encrypt_password
|
||||
|
||||
file_column :image, :magick => { :geometry => "100x100>" }
|
||||
|
||||
def after_initialize
|
||||
self.creation_time = Time.now if self.creation_time.nil?
|
||||
end
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<h2><%= @title %></h2>
|
||||
|
||||
<% if @this_user.image %>
|
||||
<%= image_tag url_for_file_column(@this_user, "image") %>
|
||||
<% end %>
|
||||
<br />
|
||||
|
||||
<% if @this_user %>
|
||||
<% if @user == @this_user %>
|
||||
<%= link_to 'New diary post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
<table>
|
||||
<tr>
|
||||
<th align="right">From</th>
|
||||
<td><%= link_to @message.sender.display_name, :controller => 'user', :action => 'view', :display_name => @message.sender.display_name %></td>
|
||||
<td>
|
||||
<% if @message.sender.image %>
|
||||
<%= image_tag url_for_file_column(@message.sender, "image") %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to @message.sender.display_name, :controller => 'user', :action => 'view', :display_name => @message.sender.display_name %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="right">Subject</th>
|
||||
|
|
|
@ -18,6 +18,21 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<h3>User image</h3>
|
||||
<% if @this_user.image %>
|
||||
<%= image_tag url_for_file_column(@this_user, "image") %>
|
||||
<% end %>
|
||||
<br />
|
||||
|
||||
<% if @user and @this_user.id == @user.id %>
|
||||
Upload an image<br />
|
||||
<%= form_tag({:action=>'upload_image'}, :multipart => true)%>
|
||||
<%= file_column_field 'user', 'image' %>
|
||||
<input type="submit" name="Upload" />
|
||||
</form>
|
||||
<% end %>
|
||||
|
||||
<h3>Description</h3?
|
||||
<div id="description"><%= simple_format(@this_user.description) %></div>
|
||||
|
||||
<% if @this_user.home_lat.nil? or @this_user.home_lon.nil? %>
|
||||
|
@ -38,6 +53,11 @@
|
|||
<% @this_user.friends.each do |friend| %>
|
||||
<% @friend = User.find_by_id(friend.friend_user_id) %>
|
||||
<tr>
|
||||
<td class="image">
|
||||
<% if @friend.image %>
|
||||
<%= image_tag url_for_file_column(@friend, "image") %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="username"><%= link_to @friend.display_name, :controller => 'user', :action => 'view', :display_name => @friend.display_name %></td>
|
||||
<td><% if @friend.home_lon and @friend.home_lat %><%= @this_user.distance(@friend).round %>km away<% end %></td>
|
||||
<td class="message">(<%= link_to 'send message', :controller => 'message', :action => 'new', :user_id => @friend.id %>)</td>
|
||||
|
|
|
@ -61,6 +61,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect '/user/confirm', :controller => 'user', :action => 'confirm'
|
||||
map.connect '/user/go_public', :controller => 'user', :action => 'go_public'
|
||||
map.connect '/user/reset_password', :controller => 'user', :action => 'reset_password'
|
||||
map.connect '/user/upload_image', :controller => 'user', :action => 'upload_image'
|
||||
map.connect '/index.html', :controller => 'site', :action => 'index'
|
||||
map.connect '/edit.html', :controller => 'site', :action => 'edit'
|
||||
map.connect '/search.html', :controller => 'way_tag', :action => 'search'
|
||||
|
|
9
db/migrate/011_add_user_image.rb
Normal file
9
db/migrate/011_add_user_image.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class AddUserImage < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column 'users', 'image', 'mediumblob'
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column 'users', 'image'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue