From 176c98ea2c0b199ae7edddc9ee71fe254ce5667b Mon Sep 17 00:00:00 2001 From: Joachim Back Date: Mon, 13 Jul 2015 21:17:41 +0200 Subject: [PATCH 1/4] Reduce number of application errors --- app/controllers/attachments_controller.rb | 2 +- app/mailers/post_mailer.rb | 9 ++++++++- app/models/event.rb | 6 +++++- app/views/search/_preview_officer_group.html.haml | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 8244c44cf..92036132a 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -78,7 +78,7 @@ def description render json: { title: @attachment.title, description: @attachment.description, - author: @attachment.author.title, + author: @attachment.author.title if @attachment.author, html: render_to_string(partial: 'attachments/description', formats: [:html], locals: {attachment: @attachment}) } end diff --git a/app/mailers/post_mailer.rb b/app/mailers/post_mailer.rb index 66f84ca16..2f014aeb4 100644 --- a/app/mailers/post_mailer.rb +++ b/app/mailers/post_mailer.rb @@ -35,7 +35,14 @@ def post_email(text, recipients, subject, sender, group, post) I18n.with_locale(recipients.first.try(:locale) || I18n.default_locale) do message = mail( - to: @to_field, from: sender.email, subject: subject, + to: @to_field, + from: + if sender.kind_of? User + sender.email + elsif sender.kind_of? String + sender + end, + subject: subject, reply_to: @reply_to ) message.smtp_envelope_to = @smtp_envelope_to_field diff --git a/app/models/event.rb b/app/models/event.rb index 7e1bee65f..e35446b90 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -16,7 +16,11 @@ def title end def to_param - "#{id} #{name} #{start_at.year}-#{start_at.month}-#{start_at.day}".parameterize + if start_at + "#{id} #{name} #{start_at.year}-#{start_at.month}-#{start_at.day}".parameterize + else + "#{id} #{name}".parameterize + end end diff --git a/app/views/search/_preview_officer_group.html.haml b/app/views/search/_preview_officer_group.html.haml index d7d75517b..f1f653e71 100644 --- a/app/views/search/_preview_officer_group.html.haml +++ b/app/views/search/_preview_officer_group.html.haml @@ -5,9 +5,9 @@ - obj.memberships.includes(:descendant).each do |membership| %p = link_to membership.user.title, membership.user - = "(#{t(:since)} #{localize membership.valid_from.to_date})" + = "(#{t(:since)} #{localize membership.valid_from.to_date if membership.valid_from})" - if obj.scope # which is the object the officer is officer for. %p = "#{t(:see_also)}:" - = link_to obj.scope.title, obj.scope \ No newline at end of file + = link_to obj.scope.title, obj.scope From d5c2b93d170d3a4a5017dc52c862a755bc256f4a Mon Sep 17 00:00:00 2001 From: Joachim Back Date: Mon, 13 Jul 2015 21:52:41 +0200 Subject: [PATCH 2/4] render json --- app/controllers/attachments_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 92036132a..c36296f70 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -78,7 +78,9 @@ def description render json: { title: @attachment.title, description: @attachment.description, - author: @attachment.author.title if @attachment.author, + if @attachment.author + author: @attachment.author.title, + end html: render_to_string(partial: 'attachments/description', formats: [:html], locals: {attachment: @attachment}) } end From eec5c72be54959f123cd225a3a15524f427c3c82 Mon Sep 17 00:00:00 2001 From: Joachim Back Date: Mon, 13 Jul 2015 22:02:27 +0200 Subject: [PATCH 3/4] render json 2 --- app/controllers/attachments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index c36296f70..f218a549d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -79,8 +79,8 @@ def description title: @attachment.title, description: @attachment.description, if @attachment.author - author: @attachment.author.title, - end + author: @attachment.author.title + end, html: render_to_string(partial: 'attachments/description', formats: [:html], locals: {attachment: @attachment}) } end From f9471bdd41a833101b2e06850c08d69fd227ad5d Mon Sep 17 00:00:00 2001 From: Joachim Back Date: Mon, 13 Jul 2015 22:24:42 +0200 Subject: [PATCH 4/4] render json 3 --- app/controllers/attachments_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index f218a549d..c383b2e0b 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -78,9 +78,12 @@ def description render json: { title: @attachment.title, description: @attachment.description, - if @attachment.author - author: @attachment.author.title - end, + author: + if @attachment.author + @attachment.author.title + else + '' + end, html: render_to_string(partial: 'attachments/description', formats: [:html], locals: {attachment: @attachment}) } end