routing to a static .md page in /public (ruby on rails 2.3.5) -


this question asked before, answer ruby on rails 3.0+

basically want put wiki pages (ie .md pages) inside public folder in 2.3.5 ruby on rails project. , want users access home of wiki page when type mysite.com/wiki (ie map /public/wiki/home.md)..

how do in ruby on rails 2.3.5? (the routing documentation online wasn't informative)

also in general if reason i'm stuck ror 2.3.5 project.. go documentation? seems official documentation pertains latest ror version (ie 3+)

i presume want markdown rendered. if serve public directory, rails won't render it.

what new controller, wikicontroller, render markdown files store somewhere lib/wiki. haven't tested of directly, should take guide, should work okay.

the controller might this:

# app/controllers/wiki_controller.rb class wikicontroller < applicationcontroller   def show     page = file.open(file.join(rails.root, 'lib', 'wiki', "#{params[:page_id]}.md"), 'r') { |f| f.read }     markdown = redcarpet::markdown.new(redcarpet::render::html, :autolink => true)     render :html => markdown.render(file.join(rails.root, 'lib', 'wiki', "#{params[:page_id]}.md"))   end end 

and add route this:

# config/routes.rb map.connect 'wiki', :controller => 'wiki', :action => 'show', :page_id => 'home' map.connect 'wiki/*page_id', :controller => 'wiki', :action => 'show', :as => :wiki 

the first route handles special case (home.md) , second allow structure wiki (including placing files in subdirectories, etc). linking /wiki/help/getting_started try render file lib/wiki/help/getting_started.md.

you have link helper method, if need link wiki page within app can call wiki_path(:page_id => 'help/getting_started').

this solution assumes you're using redcarpet markdown rendering, switch renderer like.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -