app/controllers/cas/sites/sections/contents_controller.rb in cas-cms-0.1.3 vs app/controllers/cas/sites/sections/contents_controller.rb in cas-cms-1.0.0.alpha1

- old
+ new

@@ -23,14 +23,16 @@ ActiveRecord::Base.transaction do @content.author_id = current_user.id @content.section_id = @section.id @content.tag_list = content_params[:tag_list] if content_params[:tag_list] success = @content.save! + ::Cas::Activity.create!(user: current_user, site: @site, subject: @content, event_name: 'create') associate_files(@content, :images) associate_files(@content, :attachments) end rescue ActiveRecord::RecordInvalid + Rails.logger.info "Errors: #{@content.errors.full_messages.inspect}" success = nil end if success redirect_to site_section_contents_url(@site, @section), notice: 'Noticia salva com sucesso.' @@ -60,10 +62,11 @@ ActiveRecord::Base.transaction do @content.tag_list = content_params[:tag_list] success = @content.update!(content_params) associate_files(@content, :images) associate_files(@content, :attachments) + ::Cas::Activity.create!(user: current_user, site: @site, subject: @content, event_name: 'update') end rescue ActiveRecord::RecordInvalid success = nil end @@ -88,20 +91,26 @@ @content_type = @section.section_type end def content_params @content_params ||= begin + # When no file is uploaded, when the content form is submitted the + # `file` input ends up being sent empty (e.g file: [""]). This confuses + # Rails. + params[:content].delete(:file) if params[:content][:file].map(&:presence).compact.blank? + result = params.require(:content).permit( :category_id, :title, :location, :summary, :published, :date, :text, :url, :embedded, - :tag_list + :tag_list, + :file ) unless result.keys.map(&:to_sym).include?(:published) result[:published] = true end