I have the CarrierWave gem installed. There are no galleries, as I have it setup so that photos belong to a user not a gallery.
I added a avatar
column to the Photos table. The other columns are: id, created_at, updated_at, image, name, user_id
The question is how do I set a action so the users can click 'Make Profile Image' and it will make changes to the avatar
column? This should be done by either clicking on the thumbnail version of the image or having text overlay.
A example of what I mean:
User Z uploads four photos to their profile. User Z visits their profile and selects one of their uploaded photos to be their Profile image (avatar).
class PhotosController < ApplicationController
def new
@photo = Photo.new
end
def create
@photo = Photo.new(params[:photo])
@photo.user = current_user
if @photo.save
flash[:notice] = "Successfully created photos."
redirect_to :back
else
render :action => 'new'
end
end
def resize(width, height, gravity = 'Center')
manipulate! do |img|
img.combine_options do |cmd|
cmd.resize "#{width}"
if img[:width] < img[:height]
cmd.gravity gravity
cmd.background "rgba(255,255,255,0.0)"
cmd.extent "#{width}x#{height}"
end
end
img = yield(img) if block_given?
img
end
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(paramas[:photo])
flash[:notice] = "Successfully updated photo."
redirect_to @photo.gallery
else
render :action => 'edit'
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
flash[:notice] = "Successfully destroyed photo."
redirect_to @photo.gallery
end
def avatar
@photo = Photo.find params[:photo_id]
current_user.default_photo = @photo
redirect_to '/profile'
end
end
view (shows thumb photos on profile):
<div class="parent-container">
<% @user.photos.each do |photo| %>
<%= link_to image_tag(photo.image_url(:thumb)), photo.image_url%>
<% end %></div></p>