2

I am using https://github.com/plataformatec/simple_form and am trying to send a extra parameter. I have a Task, List and ListTask models, in the new page of the of the list I want to be able to insert the number of tasks that will be added. When you submit it will send you to the new list_task page with the correct number of forms populated.

=simple_form_for @list do |s|
  =s.input :title
  =s.input :task_count
  =s.button :submit

This produces a error undefined method task_count, which makes sense because it is not a method in list.

trev9065
  • 3,371
  • 4
  • 30
  • 45
  • Possible duplicate of [rails simple\_form fields not related to the model](https://stackoverflow.com/questions/12146466/rails-simple-form-fields-not-related-to-the-model) – Fangxing Sep 13 '18 at 05:51

1 Answers1

9

if you don't want the value persisting to the db, add a virtual attribute:

class List < ActiveRecord::Base
  attr_accessor :task_count
end

this will allow you to use that attribute in the form, but that will only persist for the life of that object but it will make it into your POST params.

...otherwise, if you want it to persist to the db (which is sounds like you may). You'd add task_count as a column in your lists table (via a migration).

miked
  • 4,489
  • 1
  • 17
  • 18