Merge pull request #4 from skiprope/patch-2

Markdown preview through AJAX (/ajax/preview)
This commit is contained in:
Georg G. 2015-04-19 00:26:20 +02:00
commit fcd2ea4837
3 changed files with 20 additions and 1 deletions

View File

@ -46,4 +46,20 @@ class Ajax::QuestionController < ApplicationController
@message = "Question asked successfully."
@success = true
end
def preview
params.require :md
@message = "Failed to render markdown."
begin
@markdown = markdown(params[:md], Time.new)
@message = "Successfully rendered markdown."
rescue
@status = :fail
@success = false
return
end
@status = :okay
@success = true
end
end

View File

@ -0,0 +1,2 @@
json.partial! 'ajax/shared/status'
json.markdown @markdown if @markdown

View File

@ -81,6 +81,7 @@ Rails.application.routes.draw do
match '/create_group', to: 'group#create', via: :post, as: :create_group
match '/destroy_group', to: 'group#destroy', via: :post, as: :destroy_group
match '/group_membership', to: 'group#membership', via: :post, as: :group_membership
match '/preview', to: "question#preview", via: :post, as: :preview
end
match '/public', to: 'public#index', via: :get, as: :public_timeline
@ -89,7 +90,7 @@ Rails.application.routes.draw do
match '/notifications(/:type)', to: 'notifications#index', via: :get, as: :notifications, defaults: {type: 'all'}
match '/inbox', to: 'inbox#show', via: 'get'
match '/user/:username(/p/:page)', to: 'user#show', via: 'get', defaults: {page: 1}
match '/@:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1}
match '/@:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer_alt