Class: PhotosController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- PhotosController
- Includes:
- Viewable
- Defined in:
- app/controllers/photos_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /photos POST /photos.xml.
-
#destroy ⇒ Object
DELETE /photos/1 DELETE /photos/1.xml.
-
#edit ⇒ Object
GET /photos/1;edit.
- #index ⇒ Object
- #manage_photos ⇒ Object
-
#new ⇒ Object
GET /photos/new.
- #recent ⇒ Object
-
#show ⇒ Object
GET /photos/1 GET /photos/1.xml.
-
#update ⇒ Object
patch /photos/1 patch /photos/1.xml.
Methods inherited from BaseController
#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index
Methods included from BaseHelper
#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #tiny_mce_init_if_needed, #tiny_mce_js, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget
Methods included from LocalizedApplication
#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale
Methods included from AuthenticatedSystem
#login_by_token, #update_last_seen_at
Instance Method Details
#create ⇒ Object
POST /photos POST /photos.xml
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/photos_controller.rb', line 102 def create @user = current_user @photo = Photo.new(photo_params) @photo.user = @user @photo.tag_list = params[:tag_list] || '' @photo.album_id = params[:album_id] || '' @photo.album_id = params[:album_selected] unless params[:album_selected].blank? respond_to do |format| if @photo.save flash[:notice] = :photo_was_successfully_created.l format.html { render :action => 'inline_new', :layout => false and return if params[:inline] if params[:album_id] redirect_to user_album_path(current_user,params[:album_id]) else redirect_to user_photo_url(:id => @photo, :user_id => @photo.user) end } format.js { # render create.js.erb } else format.html { render :action => 'inline_new', :layout => false and return if params[:inline] render :action => "new" } format.js { # render create.js.erb @alert = :sorry_there_was_an_error_uploading_the_photo.l } end end end |
#destroy ⇒ Object
DELETE /photos/1 DELETE /photos/1.xml
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/photos_controller.rb', line 161 def destroy @user = User.find(params[:user_id]) @photo = Photo.find(params[:id]) if @user.avatar.eql?(@photo) @user.avatar = nil @user.save! end @photo.destroy respond_to do |format| format.html { redirect_to user_photos_url(@photo.user) } end end |
#edit ⇒ Object
GET /photos/1;edit
95 96 97 98 |
# File 'app/controllers/photos_controller.rb', line 95 def edit @photo = Photo.find(params[:id]) @user = @photo.user end |
#index ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/photos_controller.rb', line 21 def index @user = User.find(params[:user_id]) @photos = Photo.where(:user_id => @user.id).includes(:tags) if params[:tag_name] @photos = @photos.where('tags.name = ?', params[:tag_name]) end @photos = @photos.recent.page(params[:page]).per(20) = Photo.includes(:taggings).where(:user_id => @user.id).tag_counts(:limit => 20) @rss_title = "#{configatron.community_name}: #{@user.login}'s photos" @rss_url = user_photos_path(@user,:format => :rss) respond_to do |format| format.html format.rss { render_rss_feed_for(@photos, { :feed => {:title => @rss_title, :link => url_for(:controller => 'photos', :action => 'index', :user_id => @user) }, :item => {:title => :name, :description => Proc.new {|photo| description_for_rss(photo)}, :link => Proc.new {|photo| user_photo_url(photo.user, photo)}, :pub_date => :created_at} }) } format.xml { render :action => 'index.rxml', :layout => false} end end |
#manage_photos ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/photos_controller.rb', line 51 def manage_photos if logged_in? @user = current_user @photos = current_user.photos.recent.includes(:tags) if params[:tag_name] @photos = @photos.where('tags.name = ?', params[:tag_name]) end @selected = params[:photo_id] @photos = @photos.page(params[:page]).per(10) end respond_to do |format| format.js end end |
#new ⇒ Object
GET /photos/new
85 86 87 88 89 90 91 92 |
# File 'app/controllers/photos_controller.rb', line 85 def new @user = User.find(params[:user_id]) @photo = Photo.new if params[:inline] render :action => 'inline_new', :layout => false end end |
#recent ⇒ Object
17 18 19 |
# File 'app/controllers/photos_controller.rb', line 17 def recent @photos = Photo.recent.page(params[:page]) end |
#show ⇒ Object
GET /photos/1 GET /photos/1.xml
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/photos_controller.rb', line 68 def show @photo = @user.photos.find(params[:id]) update_view_count(@photo) if current_user && current_user.id != @photo.user_id @is_current_user = @user.eql?(current_user) @comment = Comment.new @previous = @photo.previous_photo @next = @photo.next_photo = Photo.(@photo) respond_to do |format| format.html # show.rhtml end end |
#update ⇒ Object
patch /photos/1 patch /photos/1.xml
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/photos_controller.rb', line 143 def update @photo = Photo.find(params[:id]) @user = @photo.user @photo.tag_list = params[:tag_list] || '' @photo.album_id = photo_params[:album_id] respond_to do |format| if @photo.update_attributes(photo_params) format.html { redirect_to user_photo_url(@photo.user, @photo) } else format.html { render :action => "edit" } end end end |