Jeff Wilson
Joined
Activity
Do you know a good resource for setting this up with mongoid?
Posted in Ideas for building a Wiki in my app
There's a pro episode on using the pipeline gem to support markdown and emoji : https://gorails.com/episodes/markdown-emoji-with-html-pipeline-gem
I used this in an application for our company and simply created a helper method in the application_helper to format any block of user imputed code:
def formatter(content)
pipeline_context = {gfm: true, asset_root: "https://a248.e.akamai.net/assets.github.com/images/icons/"}
pipeline = HTML::Pipeline.new [
HTML::Pipeline::MarkdownFilter,
HTML::Pipeline::EmojiFilter,
HTML::Pipeline::SanitizationFilter,
], pipeline_context
pipeline.call(content)[:output].to_s.html_safe
end
I can then just call <%= formatter(@post.content) %> whenever I want to support markdown or Emoji
Definitely watch the episode.
Posted in Error Handling in Ruby 4+
No problem - glad it helped.
Posted in Error Handling in Ruby 4+
If we're talking about best practice I usually do the following. First, in the routes file I set a wildcard route to a method in the application controller. (get '*unmatched_route', to: 'application#raise_not_found'). Then in the application controller I set rescues for managing errors to my static error pages.
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from Exception, with: :not_found
rescue_from ActionController::RoutingError, with: :not_found
def raise_not_found
raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
end
def not_found
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.xml { head :not_found }
format.any { head :not_found }
end
end
def error
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/500", :layout => false, :status => :error }
format.xml { head :not_found }
format.any { head :not_found }
end
end