こんにちは、私は問題があり、それを解決する方法はわかりません。私はRORの世界では本当に新しいです。RORアクティブレコードがデータを保存しないcorrecty
プリアンブル:
class CreateItineraries < ActiveRecord::Migration
def change
create_table :itineraries do |t|
t.string :title
t.string :json
t.integer :muncipality_id
t.text :description
t.boolean :published, :default => true, :null => false
t.timestamps null: false
end
end
end
2)i「は:私はは、この移行に旅程表を作成しました
1):各municiplatyは非常に多くの旅程を、持っていますve は、この移行で、旅程表へのmunicipality_idの参照を追加しました。
class AddMunicipalityIdToItineraries < ActiveRecord::Migration
def change
add_reference :itineraries, :municipality, index: true, foreign_key: true
end
end
3)私は旅程の翻訳のための別のテーブル作成しました:
今class AddTranslationTablesForItineraries < ActiveRecord::Migration
def up
Itinerary.create_translation_table!({
:title => :string
}, {
:migrate_data => true
})
end
def down
add_column :itineraries, :title, :string
Itinerary.drop_translation_table! :migrate_data => true
end
end
を私は相対的なsimple_formからのデータを保存しようとすると、問題があるが、それは旅程表のタイトルを翻訳表に保存してください。なぜですか?ここ
simple_formのコード:
<%= simple_form_for [:admin, @municipality, @itinerary], url: @url, :html => {:class => ''} do |f| %>
<%= render 'application/translation_form_heading' %>
# ...
<%= f.input :title, required: true %>
<%= f.input :description, label: 'description', :as => :ckeditor, :input_html => {ckeditor: {toolbar: get_toolbar('default')},:rows => 15} %>
<%= f.input :json, required: true, label: 'GeoJSON', as: :text, :input_html => {:rows => 15} %>
# ...
<button type="submit" class="btn btn-primary pull-right">Save itinerary</button>
<% end %>
は、多分それは初心者の質問ですが、私はあなたに感謝、本当にdon'rそれを解決する方法を知っています!
編集:itinerariesControllerのここでのコード:
class Admin::ItinerariesController < InheritedResources::Base
layout 'admin'
before_filter :authenticate_admin!
before_filter :set_page_title
load_and_authorize_resource
actions :all, :except => [:show]
belongs_to :municipality
def index
@itineraries = Itinerary.ordered
end
def new
@url = admin_municipality_itineraries_path(params[:municipality_id])
new!
end
def edit
@url = admin_municipality_itinerary_path(params[:municipality_id], params[:id])
edit!
end
def update
unless params[:translate_to].blank?
I18n.with_locale(params[:translate_to]) {
update!
}
else
update!
end
end
def set_page_title
@page_title = PointOfInterest.model_name.human(:count => 2).titleize
end
def create
create! {
admin_municipality_itineraries_path
}
end
private
def permitted_params
params.permit(:itinerary => [:id, :title, :json,:description, :municipality_id])
end
end
これを作成する場所でコントローラコードを共有できますか? – Gabbar
itinerraryコントローラですか? – Leonardo
最初に奇妙に思えるのは、 'title'だけが翻訳されていることです。多分 'description 'も翻訳される必要があります(つまり、' title'の場合と同じように移行されます)。 – MrYoshiji