I have a Movie model and an Actor model:
class Movie < ActiveRecord::Base
belongs_to :genre
has_many :reviews
has_many :actors
end
class Actor < ActiveRecord::Base
belongs_to :movies
end
These are the attributes for each model:
create_table "actors", force: :cascade do |t|
t.string "name"
t.text "bio"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "movie_id"
end
create_table "movies", force: :cascade do |t|
t.string "title"
t.integer "duration"
t.date "release_date"
t.text "plot"
t.string "director"
t.text "cast"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
When a user fills out the form to create a new movie, I want the input from the 'cast' field to save to the Actor model. What action(s) would I need in my controller and what would I need to do in my form?
I've looked at and tried the following and I'm still stuck:
Rails Updating Data in one Model from another Model's Controller
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
How can I update and save one model from another in Rails?
http://railscasts.com/episodes/196-nested-model-form-part-1
Any help is greatly appreciated, thanks!