I just using activeadmin gem:
rails generate active_admin:resource Team
rails generate active_admin:resource Players
app/models
class Team < ActiveRecord::Base
has_many :players
attr_accessible :description, :name
end
class Player < ActiveRecord::Base
belongs_to :team
attr_accessible :description, :name
end
app/controller/players_controller
class PlayersController < ApplicationController
def create
@team = Team.find(params[:team_id])
@player = @team.players.create(params[:player])
end
end
app/admin/
ActiveAdmin.register Team do
end
ActiveAdmin.register Player do
end
When I tried to create a new Player using the admin interface, I receive:
ActiveModel::MassAssignmentSecurity::Error in Admin::PlayersController#create
Can't mass-assign protected attributes: team_id
I know that I have to do something more, but what? Thanks a lot.
You need to add team_id to attr_accessible: