Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Narrative Bot certificates are ERB templates #8174

Merged
merged 1 commit into from Oct 9, 2019

Conversation

@lis2
Copy link
Contributor

commented Oct 9, 2019

There are at least two ways of rendering templates outside of the controller. The first one is Rails way enabled with Rails 5 https://evilmartians.com/chronicles/new-feature-in-rails-5-render-views-outside-of-actions
The downside of this method is that all variables need to be passed as params (I could find a way to pass the whole context)

Another way is to use instance_eval described in Erubi documentation
https://github.com/jeremyevans/erubi#usage - it works perfectly fine, however, I didn't feel very confident about using eval unless necessary.

An additional benefit of using ApplicationController.render is that if Rails would change the ERB engine in the future, this code should still work.

If you want to test it on your local, you need to be signed in and then that two URLs are generating certificates:
http://localhost:3000/discobot/certificate.svg?date=Oct+07+2019&type=standard&user_id=1
http://localhost:3000/discobot/certificate.svg?date=Oct+07+2019&type=advanced&user_id=1

Dev: https://dev.discourse.org/t/discourse-narrative-bot-should-not-be-storing-giant-strings/17130

@discoursebot

This comment has been minimized.

Copy link

commented Oct 9, 2019

You've signed the CLA, lis2. Thank you! This pull request is ready for review.

@lis2 lis2 changed the title FIX: Certificates are ERB templates FIX: Narrative Bot certificates are ERB templates Oct 9, 2019
There are at least two ways of rendering templates outside of the controller. The first one is Rails way enabled with Rails 5 https://evilmartians.com/chronicles/new-feature-in-rails-5-render-views-outside-of-actions
The downside of this method is that all variables need to be passed as params (I could find a way to pass the whole context)

Another way is to use instance_eval described in Erubi documentation
https://github.com/jeremyevans/erubi#usage - it works perfectly fine, however, I didn't feel very confident about using eval unless necessary.

An additional benefit of using `ApplicationController.render` is that if Rails would change the ERB engine in the future, this code should still work.

If you want to test it on your local, you need to be signed in and then that two URLs are generating certificates:
http://localhost:3000/discobot/certificate.svg?date=Oct+07+2019&type=standard&user_id=1
http://localhost:3000/discobot/certificate.svg?date=Oct+07+2019&type=advanced&user_id=1

Dev: https://dev.discourse.org/t/discourse-narrative-bot-should-not-be-storing-giant-strings/17130
@lis2 lis2 force-pushed the lis2:narrative-bot-string branch from 5474813 to 5599242 Oct 9, 2019
@SamSaffron

This comment has been minimized.

Copy link
Member

commented Oct 9, 2019

This looks good to me (checked out on local cause the diff is so big)

TIL the inline renders define a method on an object and then erase it.

@eviltrout this opens the door to making this extensible... simply adding an accessor to certificate_generator.rb will do the trick and then simply giving it different filenames.

@SamSaffron SamSaffron merged commit e2f9b7d into discourse:master Oct 9, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@eviltrout

This comment has been minimized.

Copy link
Member

commented Oct 9, 2019

Great, there is a customer of ours who wants to customize this and it'll be a great test of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.