Ich bin neu in der Entwicklung von Schienen und ich versuche, den auto_html Edelstein zu arbeiten, aber nichts wird jemals in das body_html Feld der DB gespeichert. Ich bekomme auch keine Fehler, also scheint es, als würde der Edelstein nicht gerade angerufen.rails auto_html gem ist nicht persistent Ergebnisse
Ich habe den Edelstein in meine gemfile und ran Bundle installiert. Mache ich etwas nicht richtig? Mein Gedanke war, dass ich keine Methode auto_html irgendwo aufrufen musste, weil ich das auto_html_for im Modell habe.
Ich bin on Rails 3.2.1 und Ruby 1.9.3p125 und auto_html 1.5.1
Modell:
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
Ausblick:
= 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 Tabellendefinition von 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
Welche Version von auto_html Gem verwenden Sie? Sie müssen nicht AutoHtml in Controller BTW enthalten. Versuche etwas in der Konsole zu experimentieren. Zum Beispiel, was ist die Ausgabe in der Konsole, wenn Sie dies tun: Video.new (: body => 'test') - Dejan Simic vor 31 Sekunden bearbeiten –
1.9.3p125: 001> Video.new (: body => "test") => # –
flynfish
1.9.3p125: 002> Video.create (: body => "test") (0.3ms) BEGIN SQL (0.7ms) INSERT INTO 'videos' (' body', 'body_html',' campaign_id', 'created_at',' updated_at') VALUES ('test', NULL, NULL, ' 2012-03-29 17:10:36 ',' 2012-03-29 17:10:36 ') (0.4ms) COMMIT => # –
flynfish