|
|
|
@ -2,6 +2,7 @@ class LibrariesController < ApplicationController
|
|
|
|
|
layout 'base_library'
|
|
|
|
|
|
|
|
|
|
before_filter :require_login, :except => [:index]
|
|
|
|
|
after_filter :increment_visit_count, only: [:show, :create, :edit, :update]
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
libraries = Library.where(nil)
|
|
|
|
@ -25,7 +26,6 @@ class LibrariesController < ApplicationController
|
|
|
|
|
return render_403 unless admin_or_self? || @library.published?
|
|
|
|
|
|
|
|
|
|
@library_applies = @library.library_applies.where(status: :refused).order('created_at desc')
|
|
|
|
|
@library.increment_visited_count!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
@ -39,10 +39,10 @@ class LibrariesController < ApplicationController
|
|
|
|
|
Libraries::SubmitService.new(@library).call
|
|
|
|
|
redirect_to publish_success_libraries_path
|
|
|
|
|
else
|
|
|
|
|
flash[:message] = '保存成功'
|
|
|
|
|
redirect_to edit_library_path(id: @library.id)
|
|
|
|
|
redirect_to library_path(id: @library.id)
|
|
|
|
|
end
|
|
|
|
|
rescue ActiveRecord::RecordInvalid => _
|
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
|
|
|
flash[:message] = e.record.errors.full_messages.join(',')
|
|
|
|
|
render 'new'
|
|
|
|
|
rescue Libraries::SubmitService::Error => ex
|
|
|
|
|
flash[:message] = ex.message
|
|
|
|
@ -63,10 +63,10 @@ class LibrariesController < ApplicationController
|
|
|
|
|
Libraries::SubmitService.new(@library).call
|
|
|
|
|
redirect_to publish_success_libraries_path
|
|
|
|
|
else
|
|
|
|
|
flash[:message] = '保存成功'
|
|
|
|
|
redirect_to edit_library_path(id: @library.id)
|
|
|
|
|
redirect_to library_path(id: @library.id)
|
|
|
|
|
end
|
|
|
|
|
rescue ActiveRecord::RecordInvalid => _
|
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
|
|
|
flash[:message] = e.record.errors.full_messages.join(',')
|
|
|
|
|
render 'edit'
|
|
|
|
|
rescue Libraries::SubmitService::Error => ex
|
|
|
|
|
flash[:message] = ex.message
|
|
|
|
@ -110,6 +110,7 @@ class LibrariesController < ApplicationController
|
|
|
|
|
def form_params
|
|
|
|
|
@_form_params ||= begin
|
|
|
|
|
hash = params[:library].presence || {}
|
|
|
|
|
hash[:tag_ids] = params[:tag_ids].to_s.split(',')
|
|
|
|
|
hash[:attachment_ids] = (params[:attachments].presence || []).values.map{|h| h[:attachment_id]}
|
|
|
|
|
hash
|
|
|
|
|
end
|
|
|
|
@ -122,4 +123,8 @@ class LibrariesController < ApplicationController
|
|
|
|
|
def admin_or_self?
|
|
|
|
|
current_library.user_id == current_user.id || admin_or_business?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def increment_visit_count
|
|
|
|
|
@library.increment_visited_count! if @library && @library.id
|
|
|
|
|
end
|
|
|
|
|
end
|