Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:45:13+00:00 2026-06-09T15:45:13+00:00

I have a posts model that I use to make blog posts on a

  • 0

I have a posts model that I use to make blog posts on a page of my site. I’d like for the content of the post to be HTML formatted, but am having trouble getting it to actually render in HTML. It only shows up as plain text on the blog page. I am using Rails_Admin if that makes a difference.


posts view:

#blog_page
- @posts_list.each do |post|
    %ul.post
        %li= post.created_at.strftime("%B %d, %Y")
        %li.title= post.title
        %li.author
            = 'By: '
            = post.author
        %li.content= RedCloth.new(post.content).to_html

= paginate @posts_list


post model:

class Post < ActiveRecord::Base
attr_accessible :content, :title, :author
has_many :comments

validates :title, :presence => true
validates :content, :presence => true

end


posts controller:

class PostsController < ApplicationController

before_filter :authenticate_user!, :only => [:new, :create]

# GET /posts
def index
    @posts_list = Post.order("created_at DESC").page(params[:page]).per(5)
    render 'blog'
end

# GET /posts/
def show
    @post = Post.find(params[:id])
    render 'show'
end

def new
    if !current_user.admin?
        redirect_to '/blog'
    end
    @post = Post.new
end

# POST /posts
def create
    @post = Post.new(params[:post])
        if current_user.admin?
          respond_to do |format|
            if @post.save
              format.html  { redirect_to('/posts', :notice => 'Post was successfully created.') }
              format.json  { render :json => @post, :status => :created, :location => @post }
        else
          flash[:notice] = 'Error creating post!<br/>'.html_safe
            @post.errors.full_messages.each do |msg|
              flash[:notice] << "<br/>".html_safe
              flash[:notice] << msg
            end
          format.html  { render :action => "new" }
          format.json  { render :json => @post.errors, :status => :unprocessable_entity }
        end
      end
    else
      redirect_to '/blog'
    end
end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:45:14+00:00Added an answer on June 9, 2026 at 3:45 pm

    Your view has to be like this:

    #blog_page
    - @posts_list.each do |post|
        %ul.post
            %li= post.created_at.strftime("%B %d, %Y")
            %li.title= post.title
            %li.author
                = 'By: '
                = post.author
            %li.content= RedCloth.new(post.content).to_html.html_safe
    
    = paginate @posts_list
    

    You could also create a helper for that:

    def post_content( post ) 
      RedCloth.new(post.content).to_html.html_safe
    end
    

    And just use it in your view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model that has many posts. Im trying to render the
I have a Topic model and a Post model. A Topic has many Posts,
I have a model form that I use to update a model. class Turtle(models.Model):
I am creating a site much like a wordpress blog whereby the front page
I have a Post model that has a datetime.date field for posted_date . I
I have a posts model... I am trying to display this model on the
So for example ... Lets say I have a Posts model and a News
Assuming I have a comments model and a posts model, What code can I
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
I'm trying to set up my EF Model. I have 2 tables: Posts and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.