darkginger
darkginger

Reputation: 690

Migrated a new column to a table and updated its form in Rails but fails to update

I am using a blog engine in my Rails project called Lines, and blog posts are contained in a table called LinesArticle.

I want to add a custom attribute to hide certain posts behind a paywall, so I ran the following migration and raked it successfully:

class AddPaywallToLinesArticles < ActiveRecord::Migration
  def change
    add_column :lines_articles, :paywall, :string
  end
end

Each blog post added to this table is posted through a form in the UI contained in my views/Lines/articles folder. I added a new text_field (where the user would write yes or no, I know I could do this through a Boolean but wanted to use a string just to test it).

<div class="input-field checkbox">
<%= f.label :paywall %><br>
<%= f.text_area :paywall%>

The form now loads and shows a text_area; however, that text is not saved when I submit the form. Example output if I check the last record in the table:

 <LinesArticle id: 5, title: "Test 2 with False", teaser: nil, insider: nil, paywall: nil> 

So the paywall column is not updating with the string I am typing in. I don't think it's an issue with the form -- I am wondering if the real issue is that I need to set some sort of permits: -- this blog engine does not have a Controller associated with it though.

Any ideas?

Upvotes: 1

Views: 20

Answers (1)

Cyzanfar
Cyzanfar

Reputation: 7136

Your problem is most likely due to a missing strong parameter in your controller:

def create
 ...
 @lineArticle = LinesArticle.create(line_article_params)
 ...
end

private

def line_article_params
  params.require(:line_article).permit(:title, :teaser, :insider, :paywall)
end

Upvotes: 1

Related Questions