2013-12-05 3 views
0

Я пытаюсь вложить форму с двумя ресурсами (Карта и местоположение). Я следую учебнику вложенных форм от Райана Бейтса, но я должен что-то пропускать.Как создать вложенную форму в Refinerycms?

Карта Модель:

module Refinery 
    module Maps 
    class Map < Refinery::Core::BaseModel 
     self.table_name = 'refinery_maps' 

     attr_accessible :name, :position, :questions_attributes 

     validates :name, :presence => true, :uniqueness => true 
     has_many :locations 

     accepts_nested_attributes_for :locations 
    end 
    end 
end 

Расположение Модель:

module Refinery 
    module Maps 
    class Location < Refinery::Core::BaseModel 

     attr_accessible :latitude, :longitude, :address, :description, :title, :position 

     validates :address, :presence => true, :uniqueness => true 
     belongs_to :map 
    end 
    end 
end 

Вид:

Controller (декоратор):

Refinery::PagesController.class_eval do 

    before_filter :new 

    private 
    def new 
     @map = Map.new 
     3.times { @map.locations.build } 
    end 

    end 

схемы:

create_table "refinery_maps_locations", :force => true do |t| 
    t.float "latitude" 
    t.float "longitude" 
    t.string "address" 
    t.string "description" 
    t.string "title" 
    t.integer "position" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
    t.integer "map_id" 
    end 

    create_table "refinery_maps", :force => true do |t| 
    t.string "name" 
    t.integer "position" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
    end 

Маршруты:

Refinery::Core::Engine.routes.draw do 

    # Frontend routes 
    namespace :maps do 
    resources :maps, :path => '', :only => [:index, :show] 
    end 

    # Admin routes 
    namespace :maps, :path => '' do 
    namespace :admin, :path => Refinery::Core.backend_route do 
     resources :maps, :except => :show do 
     collection do 
      post :update_positions 
     end 
     end 
    end 
    end 


    # Frontend routes 
    namespace :maps do 
    resources :locations, :only => [:index, :show] 
    end 

    # Admin routes 
    namespace :maps, :path => '' do 
    namespace :admin, :path => "#{Refinery::Core.backend_route}/maps" do 
     resources :locations, :except => :show do 
     collection do 
      post :update_positions 
     end 
     end 
    end 
    end 

end 

ответ

0

Вы пропускаете :locations_attributes в вашей модели карты - у вас есть :questions_attributes там вместо этого.

Кроме того, проверить этот драгоценный камень для refinerycms вложенных моделей - https://github.com/llamadigital/refinerycms-nested_models

Просто замените «nested_models» с именем, который вы хотите, чтобы гнездиться. Он работает намного лучше с нефтеперерабатывающим заводом, чем вложенные формы.

Смежные вопросы