What Do I Need to Do to Get the Blog to Work in Rails 4.2

How to add middleware in Rails 4.2 application

Middleware has to have an accompanying module / class, and needs to be loaded in the app before it can be referenced. The way to do this in Rails is with autoloading (lib files aren't autoloaded by default):

#config/application.rb
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.middleware.use "ResponseTimer"

The above should work for you.

how display certain branch of blog?

Okay, I've written about this before; there are certain things which you've got to fix with the Railscast recommendations:

  1. Put it in a partial, not helper (it gives greater autonomy)
  2. You need to make sure your structure is as versatile as you need

--

Here's how I'd do what you're trying to achieve:

#app/controllers/messages_controller.rb
class MessagesController < ApplicationController
def index
@messages = Message.all #-> could filter this to only retrieve id=3
#@messages = Message.find "3" #-> like this
end
end

#app/views/messages/index.html.erb
<% render @messages.arrange(order: :created_at) %>

#app/views/messages/_message.html.erb
# ... single message output code ... #
<%= render message.children if message.has_children? && message.id == "3" %>

You could then extrapolate the conditional functionality into a helper. If you describe your functionality more specifically, I'll be able to make a helper to define it.

Any gem for designing a blog post in Rails with syntax highlighting and inline image attachment?

Obtvse, an open source blog engine inspired by Svbtle does pretty much exactly what you are looking for.

It uses Coderay for syntax highlighting which is a pure ruby library and does not depend on javascript, and Markdown (through Kramdown) for editing posts rather than a WYSIWYG solution like CKEDITOR which IMHO is a more sane choice - especially for technically inclined.

Backend based syntax highlighting plays well with RSS readers as opposed to javascript based solutions.

You can either use the application and customize as per your requirements, or take a look at the implementation and use that to build your own solution.

Alternatively if you are specifically inclined towards using CKEditor you might want to take a look at this plugin which integrates CKEditor with CodeMirror, which is among the most popular solutions for code editing and highlighting in javascript. For displaying the snippets you can also use CodeMirror in a readonly mode as described in this manual. This will ensure that you get the exact same syntax highlighting while editing as well in post view page.



Related Topics



Leave a reply



Submit