Ho la seguente metodo di supporto:Attributo salvato in fase di sviluppo, ma non in produzione
def parse_potential_followers(params)
t_id = TestSet.where(:test_name => params[:test_set][:test_name]).pluck(:id)[0].to_i
screen_names = params[:potential_followers].first[1].split("\n").reject(&:blank?)
screen_names.each do |s|
potential_follower = PotentialFollower.new(
:screen_name => s,
:test_sets_id => t_id,
:status => 'new',
:slug => generate_slug([t_id.to_s, s])
)
potential_follower.save
end
end
Il problema è che quando chiamo questo metodo, il test_sets_id viene saltato quando si inserisce i dati nella tabella nell'ambiente di sviluppo , ma non nell'ambiente di produzione. Gli altri tre attributi vengono salvati correttamente.
Tutti gli attributi sono definiti nella tabella potential_followers.
devo anche tutti gli attributi nel metodo potential_follower_params nella 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
test_sets_id è definito come un numero intero nella tabella. Ho persino provato a codificare il valore di t_id:
t_id = 12
Ma non funzionerebbe ancora in produzione.
Ecco cosa c'è nella modelli/potential_follower.rb:
class PotentialFollower < ActiveRecord::Base
belongs_to :TestSet
end
Ecco il metodo in test_sets_contoller.rb:
def create
@test_set = TestSet.new(test_set_params)
respond_to do |format|
if @test_set.save
parse_potential_followers(params)
format.html { redirect_to @test_set, notice: 'Test set was successfully created.' }
format.json { render :show, status: :created, location: @test_set }
else
format.html { render :new }
format.json { render json: @test_set.errors, status: :unprocessable_entity }
end
end
end
Tutte le idee?
Puoi pubblicare il codice per 'PotentialFollower'? –
Cosa intendi per codice per PotentialFollower? Conttoller? Vista? Modello? – EastsideDeveloper
Scusa, quindi Modello. –