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

  • Home
  • SEARCH
  • 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 6331481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:04:39+00:00 2026-05-24T18:04:39+00:00

I have a very simple model using Mongoid. I’ve added the use of Redcarpet

  • 0

I have a very simple model using Mongoid. I’ve added the use of Redcarpet to parse the MD and store it. However during update_attributes it is throwing an exception. Running the model and running the update through rails c works fine.

class Post
  include Mongoid::Document
  field :contents_markdown
  field :contents

  key :title

  before_create :markdown
  before_save :markdown

  protected
  def markdown
    if self.contents_markdown
      self.contents = Redcarpet.new(self.contents_markdown).to_html.html_safe
    end
  end
end

Here is the controller that blows up.

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.json { head :ok }
    else
      format.html { render action: "edit" }
      format.json { render json: @post.errors, status: :unprocessable_entity }
    end
  end
end

Here is the exception and stacktrace. The line numbers will be slightly off as I have removed stuff from the model.

uninitialized constant Post::Redcarpet

app/models/post.rb:20:in `markdown'
app/controllers/posts_controller.rb:62:in `block in update'
app/controllers/posts_controller.rb:61:in `update'

If it matters, I’m running MRI 1.9.2-p290 and Rails 3.1-rc5.

Edit –
This all works fine when running tests and running through the console. However going through the controller to update/create the model seems to always fail. Additionally from the stacktrace, you can see the model is in the standard location.

  • 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-05-24T18:04:39+00:00Added an answer on May 24, 2026 at 6:04 pm

    You might be missing a require or a gem declaration depending on how you’re using Redcarpet.

    The Rails auto-loader will generally catch these if that is defined in a standard location like app/models or, as is optional, lib/.

    Usually you can fix this by putting the appropriate require statement in a config/initializers/redcarpet.rb type file, or altering your Gemspec as necessary.

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

Sidebar

Related Questions

I have created a very simple Entity Framework 4.0 model using VS2010 Professional. Ignore
I have two very simple classes Submission and Store class Submission(models.Model): title = models.CharField(max_length=50,
Hey, I have a maybe very simple problem using the PreLoadFcn in my model.
I am currently using Django Users model. Very simple. However, I'd like to add
I have this very simple TPH Model. When I add an object using context.TIImport.AddObject(tiObj)
i have very simple problem. I need to create model, that represent element of
I have a very simple WPF application in which I am using data binding
I have a very simple model that includes the auto-filled field much like 'created'.
Ok, I have a model that is very simple: ServiceType(id: integer, title: string, duration:
Consider a very simple model where we have locations and each location can have

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.