for_tag has two attributes, 1: :level_id
2: :title
.
User is entering both values but in :title
, entering values as
Math,English,ETC and am splitting this into array as
@test = params.requrie(:service).permit(:title)[:title]
I need to create entering in DB with the same :level_id
title:math,level_id:1
title:English,level_id:1
in my Service Controller am trying this.
def create
@qure = params.require(:service).permit(:level_id)[:level_id]
@test = params.require(:service).permit(:title)[:title]
@gain = @test.split(",")
@gain.each do |fil|
Service.new(fil,@qure)
end
redirect_to root_url
end
this giving me an error
When assigning attributes, you must pass a hash as an argument.
my Migration
def change
create_table :services do |t|
t.string :title
t.integer :level_id
t.timestamps null: false
end
end
You can just do the following:
I've also used create! in the method but you should consider using save and checking the return value if you want to use validations. The above will raise an error if there are validation issues.