I am new to Rails but have used PHP extensively over the years. I am building a simple blog (I know) to get my skills up in the MVC/Rails world.
I have the basics working but have spent the weekend trying to get Maruku to work eg a post body saved from a text area with Markdown Extra markup to the db and then back again to the browser.
I used the following code in my Post model but I get an error when I try to load /posts - "undefined local variable or method `maruku' for #"
class Post < ActiveRecord::Base
validates :name, :presence => true
validates :title, :presence => true,
:length => { :minimum => 5 }
validates :content, :presence => true
validates :excerpt, :presence => true
has_many :comments, :dependent => :destroy
maruku.new(:content).to_html
end
I also tried something similar in my Posts Controller that I found on here. Then called @post.content in my Show view but get an error:
body = maruku.new(post.body)
post.body = body.to_html
I am dead sure it's my noob brain being dead but any help or direction would be great as I have fought with this for two days now. BTW I am using maruku as I need Markdown Extra as my old blog posts are all formatted that way.
Thanks
UPDATED - PostsController
class PostsController < ApplicationController
# GET /posts
# GET /posts.xml
def index
@posts = Post.find(:all, :order => 'created_at DESC')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to(@post, :notice => 'Post was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
end