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