How to send data from a form to the model for update?


#1

I have a page that contains multiple tabs. In the movies_controller of
the Movie tab I have this:

def update
@tab = params[:tab] || ‘’
if @tab.blank?
throw ‘no tab given to MoviesController::update()’
elsif !tabs.keys.include?(@tab)
throw “tab ‘#{params[:tab]}’ not supported in
MoviesController::update()”
else # it’s a valid tab

get the valid params for the given tab:

safeparams = send("#{@tab}_params")

try to update the location with the params:

movie = Movie.find(params[:id])

movie.update(safeparams)
end
end

def actor_params

params.require(:location).permit :address_ids

params.require(:movie).permit(actors[:first_name, :last_name, :role,
:bio])
end

And then in the movie.rb model, I have this.

def actors=(actors)
actors.each { |a|
Actors.update(a)
}
end

And in my actor.html.erb

<%=form_for @movie do |l|%>
<% @movie.actors.each do |f| %>

First Name

Last Name

Role

Bio

<% end %> Back to movies Save <%end%>

In the actor.html.erb, how do I allow the user the click a +add button
to dynamically add a new actor form for enter more than one actor at a
time?

In the movie_controller/actor_params, how do I pass an array of all the
actors from the actor.html.erb page to the movie.rb model?

In the movie.rb model actors method, how do I access the Actor.rb model
to update each actor in the array that’s being passed?

I’m not sure if I make any sense here but basically what I’m trying to
do is updating the actor.html.erb form tab to the Actors table. Any help
is much appreciated.