I am new to rails development and I am trying to get the auto_html gem to work, but nothing ever gets saved to the body_html field of the DB. I am not getting any errors either, so it seems like the gem just isn’t getting called.
I have included the gem in my gemfile and ran bundle install. Am I not doing something correctly? My thought was that I didn’t need to call any auto_html method anywhere because I have the auto_html_for in the model.
I am on Rails 3.2.1 and ruby 1.9.3p125 and auto_html 1.5.1
Model:
class Video < ActiveRecord::Base
belongs_to :campaign
auto_html_for :body do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
end
Controller:
class VideosController < ApplicationController
def new
@video = Video.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @video }
end
end
def create
@video = Video.new(params[:video])
respond_to do |format|
if @video.save
format.html { redirect_to videos_path(:campaign => "#{@video.campaign_id}"), notice: 'Video was successfully created.' }
format.json { render json: @video, status: :created, location: @video }
else
format.html { render action: "new" }
format.json { render json: @video.errors, status: :unprocessable_entity }
end
end
end
View:
= simple_form_for @video do |f|
.field
= f.hidden_field :campaign_id, :value => "#{params[:campaign]}"
= f.text_area :body
.actions
= f.submit 'Save'
EDIT: videos table definition from schema.rb
create_table "videos", :force => true do |t|
t.text "body"
t.text "body_html"
t.integer "campaign_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
auto_html_for didn’t worked well with Rails 3.2.1+
Install the latest auto_html version (1.5.2).