Class: ClippingsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- ClippingsController
- Defined in:
- app/controllers/clippings_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /clippings POST /clippings.xml.
-
#destroy ⇒ Object
DELETE /clippings/1 DELETE /clippings/1.xml.
-
#edit ⇒ Object
GET /clippings/1;edit.
-
#index ⇒ Object
GET /clippings GET /clippings.xml.
- #load_images_from_uri ⇒ Object
-
#new ⇒ Object
GET /clippings/new.
- #new_clipping ⇒ Object
-
#show ⇒ Object
GET /clippings/1 GET /clippings/1.xml.
- #site_index ⇒ Object
-
#update ⇒ Object
patch /clippings/1 patch /clippings/1.xml.
Methods inherited from BaseController
#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_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 /clippings POST /clippings.xml
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/controllers/clippings_controller.rb', line 134 def create @user = current_user @clipping = @user.clippings.new(clipping_params) @clipping.user = @user @clipping.tag_list = params[:tag_list] || '' respond_to do |format| if @clipping.save! flash[:notice] = :clipping_was_successfully_created.l format.html { unless params[:user_id] redirect_to @clipping.url rescue redirect_to user_clipping_url(@user, @clipping) else redirect_to user_clipping_url(@user, @clipping) end } else format.html { render :action => "new" } end end end |
#destroy ⇒ Object
DELETE /clippings/1 DELETE /clippings/1.xml
176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/clippings_controller.rb', line 176 def destroy @user = User.find(params[:user_id]) @clipping = Clipping.find(params[:id]) @clipping.destroy respond_to do |format| format.html { redirect_to user_clippings_url(@user) } end end |
#edit ⇒ Object
GET /clippings/1;edit
127 128 129 130 |
# File 'app/controllers/clippings_controller.rb', line 127 def edit @clipping = Clipping.find(params[:id]) @user = User.find(params[:user_id]) end |
#index ⇒ Object
GET /clippings GET /clippings.xml
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/clippings_controller.rb', line 39 def index @user = User.find(params[:user_id]) @clippings = Clipping.includes(:tags).where(:user_id => @user.id).order("clippings.created_at DESC") @clippings = @clippings.where('tags.name = ?', params[:tag_name]) if params[:tag_name] @clippings = @clippings.page(params[:page]) @tags = Clipping.includes(:taggings).where(:user_id => @user.id).tag_counts(:limit => 20) @clippings_data = @clippings.collect {|c| [c.id, c.image_url, c.description, c.url ] } @rss_title = "#{configatron.community_name}: #{@user.login}'s clippings" @rss_url = user_clippings_path(@user,:format => :rss) respond_to do |format| format.html # index.rhtml format.js { render :inline => @clippings_data.to_json } # format.widget { render :template => 'clippings/widget', :layout => false } format.rss { render_rss_feed_for(@clippings, { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'index', :user_id => @user) }, :item => {:title => :title_for_rss, :description => Proc.new {|clip| description_for_rss(clip)}, :link => :url, :pub_date => :created_at} }) } end end |
#load_images_from_uri ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/clippings_controller.rb', line 86 def load_images_from_uri uri = URI.parse(params[:uri]) begin doc = Hpricot( open( uri ) ) rescue return end @page_title = (doc/"title") # get the images @images = [] (doc/"img").each do |img| begin if URI.parse(URI.escape(img['src'])).scheme.nil? img_uri = "#{uri.scheme}://#{uri.host}/#{img['src']}" else img_uri = img['src'] end @images << img_uri rescue nil end end respond_to do |format| format.js end end |
#new ⇒ Object
GET /clippings/new
121 122 123 124 |
# File 'app/controllers/clippings_controller.rb', line 121 def new @user = User.find(params[:user_id]) @clipping = @user.clippings.new end |
#new_clipping ⇒ Object
113 114 115 116 117 118 |
# File 'app/controllers/clippings_controller.rb', line 113 def new_clipping @user = current_user @clipping = @user.clippings.new({:url => params[:uri], :description => params[:selection]}) @post = @user.posts.new_from_bookmarklet(params) render :action => "new_clipping", :layout => false end |
#show ⇒ Object
GET /clippings/1 GET /clippings/1.xml
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/clippings_controller.rb', line 73 def show @user = User.find(params[:user_id]) @clipping = Clipping.find(params[:id]) @previous = @clipping.previous_clipping @next = @clipping.next_clipping @related = Clipping.(@clipping) respond_to do |format| format.html # show.rhtml end end |
#site_index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/clippings_controller.rb', line 12 def site_index @clippings = Clipping.includes(:tags).order(params[:recent] ? "created_at DESC" : "clippings.favorited_count DESC") @clippings = @clippings.where('tags.name = ?', params[:tag_name]).references(:tags) if params[:tag_name] @clippings = @clippings.where('created_at > ?', 4.weeks.ago) unless params[:recent] @clippings = @clippings.page(params[:page]) @rss_title = "#{configatron.community_name}: #{params[:popular] ? :popular.l : :recent.l} "+:clippings.l @rss_url = rss_site_clippings_path respond_to do |format| format.html format.rss { render_rss_feed_for(@clippings, { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'site_index') }, :item => {:title => :title_for_rss, :description => Proc.new {|clip| description_for_rss(clip)}, :link => Proc.new {|clip| user_clipping_url(clip.user, clip)}, :pub_date => :created_at} }) } end end |
#update ⇒ Object
patch /clippings/1 patch /clippings/1.xml
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/controllers/clippings_controller.rb', line 158 def update @user = User.find(params[:user_id]) @clipping = Clipping.find(params[:id]) @clipping.tag_list = params[:tag_list] || '' if @clipping.update_attributes(clipping_params) respond_to do |format| format.html { redirect_to user_clipping_url(@user, @clipping) } end else respond_to do |format| format.html { render :action => "edit" } end end end |