Last active
September 20, 2022 03:16
-
-
Save windy/7860660e5aa21ae63051 to your computer and use it in GitHub Desktop.
如何单独使用 Rails 的路由系统
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test for Rails 4.1.9 | |
# file: app/models/forum_markdown.rb | |
class ForumMarkdown | |
class DummyController | |
def logger | |
RAILS_DEFAULT_LOGGER | |
end | |
def headers | |
{} | |
end | |
def _prefixes | |
end | |
end | |
def self.render(options, assigns = {}) | |
viewer = ActionView::Base.new(File.join(Rails.root, 'app/views'), assigns, DummyController.new) | |
helper = Rails.application.routes.url_helpers | |
if options[:locals] | |
options[:locals][:helper] = helper | |
end | |
viewer.render options | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ForumMarkdown.render file: 'xx.md.erb', locals: { video_course: video_course } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <%= video_course.name %> | |
 %>) | |
## 课程介绍 | |
<%= video_course.description %> | |
更多请点击: [课程详情](<%= helper.video_course_url(video_course) %>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment