2017-11-03 1 views
1

안녕하세요 여러분, 문제가 생기고 그것을 해결하는 방법을 모릅니다. 전 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 
+0

컨트롤러 코드는이 위치에서 공유 할 수 있습니까? – Gabbar

+0

itinerrary 컨트롤러를 의미합니까? – Leonardo

+0

이상하게 보이는 첫 번째 것은 '제목'만 번역된다는 것입니다. '설명'을 번역해야 할 수도 있습니다 (예 : '제목'과 동일한 방식으로 이전 됨). – MrYoshiji

답변

0

봅니다

private 
def permitted_params 
    params.permit(:itinerary => [:id, :title, :description, :municipality_id, :json]) 
end 

당신은 항상 마지막

에 PARAMS에서 JSON 값을 허용 할 필요가 컨트롤러에서이 하나를 업데이트하기
+0

다른 솔루션이 작동하지 않습니까? – Leonardo

+0

def 편집 @url = admin_municipality_itinerary_path (params [: municipality_id], params [: id]) 편집하십시오! 끝내고 편집을 공유하십시오! 코드, 당신이이 파일에 대한 관심 파일을 만들었습니까?, 나는 당신이 여기서 무엇을하고 있는지 얻지 못하고 있습니까? 내 편집 func에서 –

+0

내가 정의 : url : "@ url = admin_municipality_itinerary_path (params [: municipality_id], params [: id])" 다음 "편집!" – Leonardo

관련 문제