Reputation: 6639
Rails 4.2.1
Ruby 2.1.5
I have the following helper method:
def parse_potential_followers(params)
t_id = TestSet.where(:test_name => params[:test_set][:test_name]).pluck(:id)
screen_names = get_screen_names
screen_names.each do |s|
potential_follower = PotentialFollower.new(
:screen_name => s,
:test_sets_id => t_id,
:status => 'new',
:slug => generate_slug([t_id, s])
)
logger.info("Test Set ID: #{t_id}")
potential_follower.save
end
end
The problem is that when I call this method, the test_sets_id is skipped when data is inserted in the table. The three other attributes are saved fine.
I verified through logger.info that t_id is valid.
All the attributes are defined in the potential_followers table.
I also have all the attributes in the potential_follower_params method in the potential_followers_controller.rb:
def potential_follower_params
params.require(:potential_follower).permit(:screen_name, :test_sets_id, :connections, :status,
:slug, :created_at, :updated_at)
end
What am I forgetting?
t_id is an array (result of ActiveRecord query). If t_id is changed to t_id[0] when used in the hash, it will work fine
Upvotes: 0
Views: 41
Reputation: 526
My guess is the data type is different. Maybe you are trying to save string as an integer?
Upvotes: 1
Reputation: 1923
You get t_id
by
t_id = TestSet.where(:test_name => params[:test_set][:test_name]).pluck(:id)
which is an array. Probably you should try to get a variable with integer
type instead of array
. If your test_sets_id
is an integer
, the value in array won't be saved.
Upvotes: 2