Created
August 7, 2014 14:45
-
-
Save siwilkins/5c6e35122be9be2cb8b8 to your computer and use it in GitHub Desktop.
Fixed controller to resolve problem with dragonfly caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin::SermonsController < ApplicationController | |
expose(:sermons) { policy_scope(Sermon) } | |
expose :sermon, attributes: :sermon_params, finder: :find_by_url | |
expose(:paginated_sermons) { sermons.page(params[:page]) } | |
before_action :authorize_sermon, except: :index | |
def index | |
authorize(sermons) | |
end | |
def new;end | |
def create | |
if sermon.save | |
flash[:success] = 'Sermon successfully uploaded.' | |
redirect_to [:admin, sermon] | |
else | |
render action: 'new' | |
end | |
end | |
def show;end | |
def edit;end | |
def update | |
if sermon.save | |
flash[:success] = 'Sermon successfully updated.' | |
redirect_to admin_sermons_path | |
else | |
render action: 'edit' | |
end | |
end | |
def destroy | |
sermon.destroy | |
flash[:success] = 'Sermon deleted.' | |
redirect_to admin_sermons_path | |
end | |
private | |
def sermon_params | |
# This is the key line - both :image and :retained_image were missing, | |
# so the image attribute wasn't going to work full stop. | |
params.require(:sermon).permit(:title, :preacher, :date, :summary, :audio, | |
:audio_cache, :image, :retained_image, :passage, :keywords) | |
end | |
def authorize_sermon | |
authorize(sermon) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment