Class: PicturesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PicturesController
- Defined in:
- app/controllers/pictures_controller.rb
Instance Method Summary collapse
- #create_comment ⇒ Object
-
#index ⇒ Object
View the index of picture, there are All pictures with pagination.
-
#show ⇒ Object
View only one picture.
Methods included from Pictrails::CachingMethods
Instance Method Details
#create_comment ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/pictures_controller.rb', line 29 def create_comment unless request.post? flash[:notice] = 'no comment save because GET request' redirect_to picture_url(Picture.find(params[:comment][:picture_id])) return end @comment = Comment.create(params[:comment]) @comment.ip = request.remote_ip if @comment.save flash[:notice] = 'Your comment is save' redirect_to picture_url(@comment.picture) else flash[:notice] = 'Your comment failed' @picture = Picture.find(params[:comment][:picture_id]) prepare_picture render :action => 'show' end end |
#index ⇒ Object
View the index of picture, there are All pictures with pagination
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/pictures_controller.rb', line 7 def index if params[:gallery_id] redirect_to gallery_url(Gallery.find_by_permalink(params[:gallery_id])) else @pictures = Picture.paginate :page => params[:page], :per_page => this_webapp.pictures_pagination end respond_to do |format| format.html end end |
#show ⇒ Object
View only one picture
21 22 23 24 25 26 27 |
# File 'app/controllers/pictures_controller.rb', line 21 def show @picture = Picture.find_by_permalink params[:id] prepare_picture @comment = @picture.comments.new rescue ActiveRecord::RecordNotFound render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 end |