안녕하세요 여러분, 문제가 생기고 그것을 해결하는 방법을 모릅니다. 전 ROR의 세계에서 정말 새롭습니다.ROR Active Record not data 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) '는 : 나 이 이주 여정 테이블을 만든
1) : 각 municiplaty 너무 많은 일정을 가지고 은이 이전과 함께 일정표에 대한 municipality_id 참조를 추가했습니다.
내가 에게 상대 simple_form에서의 데이터를 저장하려고하면 이제 문제는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
: 내가 했습니다 6,
class AddMunicipalityIdToItineraries < ActiveRecord::Migration def change add_reference :itineraries, :municipality, index: true, foreign_key: true end end
3)는 일정의 번역 또 다른 테이블을 생성 여행 표의 제목을 번역 표에만 저장하십시오. 왜?! 여기
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
이상하게 보이는 첫 번째 것은 '제목'만 번역된다는 것입니다. '설명'을 번역해야 할 수도 있습니다 (예 : '제목'과 동일한 방식으로 이전 됨). – MrYoshiji