Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PostsController < ApplicationController
- def index
- @posts = Post.all.limit(10).order(id: :desc)
- @post = Post.new
- @instagram = Instagram.user_recent_media("3900669", {:count => 18})
- @cover = Cover.last.url
- if params.has_key?(:search)
- @posts = Post.search(params[:search]).order("id DESC").limit(10)
- else
- @posts = Post.all.order('id DESC').limit(10)
- end
- @current = request.original_url.split('/')[4].to_i
- end
- def new
- @post = Post.new
- end
- def create
- @post = Post.new(post_params)
- if @post.save
- redirect_to "http://178.62.102.154/admin"
- end
- end
- before_filter :authenticate_user!, only: [:manage, :new, :edit, :destroy, :admin]
- def manage
- @posts = Post.all.limit(10).order(id: :desc)
- if params[:search]
- @posts = Post.search(params[:search]).order("id DESC").limit(10)
- else
- @posts = Post.all.order('id DESC').limit(10)
- end
- @count = Post.count
- if @count % 10 > 0
- @pages = (@count / 10) + 1
- else
- @pages = (@count / 10)
- end
- @current = request.original_url.split('/')[5].to_i
- @per_page = Post.limit(10).offset(@current*10-10).order(id: :desc)
- end
- def destroy
- @posts = Post.find(params[:id])
- if @posts.destroy
- redirect_to "http://178.62.102.154:3000/admin/manage/1"
- end
- end
- def edit
- @posts = Post.find(params[:id])
- end
- def inner
- @slug = request.original_url.split('/')[4]
- @post = Post.select("content").where(slug: @slug).last.content
- @instagram = Instagram.user_recent_media("3900669", {:count => 18})
- end
- def admin
- end
- def type
- render partial: "type", locals: { count: 30 }
- end
- def post_params
- params[:post][:image] = [:image1, :image2, :image3].map {|k| params[k] }.join(" ")
- title = params[:post][:title]
- params[:post][:slug] = title.gsub(" ", "-")
- params.require(:post).permit(:title, :content, :category, :post_type, :image, :date, :slug)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement