Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.13 KB | None | 0 0
  1. class BookmarksController < ApplicationController
  2.  
  3.     def index
  4.         @title = "Index"
  5.         if params[:tag]
  6.             @bookmarks = Bookmark.tagged_with(params[:tag])
  7.         else
  8.             @bookmarks = Bookmarks.all
  9.         end
  10.     end
  11.  
  12.     def show
  13.         @title = "View Bookmark"
  14.         @bookmark = Bookmark.find(params[:id])
  15.         @bookmark.increment!(:view_count)
  16.     end
  17.  
  18.     def new
  19.         @title = "Create Bookmark"
  20.         @bookmark= Bookmark.new
  21.         @user= User.all
  22.     end
  23.  
  24.     def create
  25.         @bookmark = Bookmark.new(params[:bookmark])
  26.         if @bookmark.save
  27.           redirect_to bookmark_url(@bookmark), :notice => "Created successfully"
  28.         else
  29.           render "new"
  30.         end
  31.     end
  32.  
  33.     def edit
  34.         @title = "Edit Bookmark"
  35.         @bookmark = Bookmark.find(params[:id])
  36.         @user= User.all
  37.     end
  38.  
  39.     def update
  40.         @bookmark = Bookmark.find(params[:id])
  41.  
  42.         if @bookmark.update_attributes(params[:bookmark])
  43.           redirect_to @bookmark, :notice => "Updated!"
  44.  
  45.         else
  46.           render "edit"
  47.         end
  48.     end
  49.  
  50.     def destroy
  51.         @bookmark = Bookmark.find(params[:id])
  52.  
  53.         @bookmark.destroy
  54.  
  55.         redirect_to root_path, :notice => "Deleted"
  56.     end
  57.    
  58.     def popular
  59.         @title = "Popular"
  60.         @bookmarks = Bookmark.all
  61.     end
  62.  
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement