How to use Nested forms
First I know this is a bad place to ask how-to question. I don’t see any other groups that would allow me to communicate (i.e. slack)
I’m attempting to setup a nested form using fae. I’ve reviewed the documentation, but something is unclear so I’m getting errors. Wanted to see if anyone can help me with issue.
Error NoMethodError in Admin::Itinerary1s#new undefined method `link' for #Itinerary1:0x007fa1555e05d0
= simple_form_for(['admin', @item], html: {multipart: true, novalidate: true, class: 'js-file-form'}, remote: true, data: {type: "html"}) do |f|
= fae_input f, :name
= fae_input f, :link
= fae_input f, :start_date
= fae_input f, :end_date
My setup
- Created a activity model ( name, body, active)
class Activity1 < ActiveRecord::Base
include Fae::BaseModelConcern
belongs_to :itinerary, touch: true
def fae_nested_parent
:itinerary
end
def fae_display_field
name
end
belongs_to :Itinerary
end
- Created a itinerary model (name, body, position, on_stage, on_prod, active)
class Itinerary1 < ActiveRecord::Base
include Fae::BaseModelConcern
def fae_display_field
name
end
acts_as_list add_new_at: :top
default_scope { order(:position) }
end
-
Added activity to navigation
-
Update _form.html.slim for itinerary
= simple_form_for(['admin', @item]) do |f|
header.content-header.js-content-header
== render 'fae/shared/form_header', header: @klass_name
== render 'fae/shared/errors'
main.content
= fae_input f, :name
= fae_input f, :body
= fae_input f, :active
== render 'admin/activity1s/form'
Also update routes, but really don’t think it’s needed.
namespace :admin do
resources :itinerary1s do
resources :activity1s
end
resources :articles
resources :article_categories
end
You don't list link as an attribute on Itinerary1 but you're calling it on the form with = fae_input f, :link. Can you paste in your schema file? If it's not there you'll have to add it as an attribute or remove it from the form.
thanks
Here is a view into my migration file, but I do agree the link attribute is part of the Activity1 model. I'm creating a new Itinerary and was thinking that I would have Activity form nested when I click new. thanks for your help.
class CreateItinerary1s < ActiveRecord::Migration
def change
create_table :itinerary1s do |t|
t.string :name
t.text :body
t.integer :position
t.boolean :on_stage
t.boolean :on_prod
t.boolean :active
t.timestamps null: false
end
end
end
class CreateActivity1s < ActiveRecord::Migration
def change
create_table :activity1s do |t|
t.string :name
t.string :link
t.date :start_date
t.date :end_date
t.references :Itinerary, index: true, foreign_key: true
t.timestamps null: false
end
end
end
It'll be hard to debug this without looking at the app for full context. Based on the error the @item in the first form is an Itinerary1 instance while it looks like the form contains attributes for Activity1. If you have an example app recreating the issue you can post, I may have time to take a peek and send you in the right direction.
thanks