user3058963
user3058963

Reputation: 105

Save Array in rails 4

I'm trying to keep my array in mysql with rails 4.

controller.rb

def emission_params
  params.require(:emission).permit(:name,:key,:phone,:address,:country,:state,:city,:email,:template,:content,:news_source)
end

In my def create

  def create
@emission = Emission.new(emission_params)
  end

The problem is that if I add the following does not keep the array in the database.

def create
  @emission = Emission.new(emission_params)
  @emission.news_source = params[:news_source]
end

Because you can not save only the first example unused @emission.news_source = params [: NEWS_SOURCE] ??

Upvotes: 0

Views: 68

Answers (2)

thedanotto
thedanotto

Reputation: 7307

I was able to get this to work in a development environment...

params.require(:emission).permit(:name, :key, :phone, :address, :country, :state, :city, :email, :template, :content, {news_source: []})

Upvotes: 1

Sunil Kumar B G
Sunil Kumar B G

Reputation: 26

def emission_params
  params.require(:emission).permit(:name, :key, :phone, :address, :country, :state, :city, :email, :template, :content, news_source: [])
end

use "[]" after array attribute.

Upvotes: 0

Related Questions