Forum: Ruby on Rails How to send data from a form to the model for update?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Charlie L. (Guest)
on 2016-09-28 15:35
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
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])


def actor_params
# params.require(:location).permit :address_ids
params.require(:movie).permit(actors[:first_name, :last_name, :role,

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

def actors=(actors)
actors.each { |a|

And in my actor.html.erb

<%=form_for @movie do |l|%>
<% @movie.actors.each do |f| %>
<label for="first_name">First Name</label>
<input type="text" name="movie[actors][<>][first_name]"
id="first_name" value="<%=f.first_name%>"/>
<label for="last_name">Last Name</label>
<input type="text" name="movie[actors][<>][last_name]"
id="last_name" value="<%=f.last_name%>"/>
<label for="bio">Role</label>
<input type="text" name="movie[actors][<>][bio]" id="role"
<label for="bio">Bio</label>
<input type="text" name="movie[actors][<>][bio]" id="bio"
<% end %>
<a class="button" href="/movies">Back to movies</a>
<a class="action button" href="#" onclick=";return

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

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.
This topic is locked and can not be replied to.