0

I am trying to use this gem activerecord-reputation-system https://github.com/twitter/activerecord-reputation-system

However that is not the problem I am running into, I am running into a problem with how ActiveRecord works with accepting params using form_for

Currently I have the :teacher param being saved in the update method of the controller like this:

@course.add_evaluation(key,  params[:teacher],   current_user)

In my view, this is the form I am using to submit to the Course

= form_for @course do |f|
  = f.number_field :teacher
  = f.submit

When you submit the form it gives this error

undefined method `teacher' for #<Course:0x007f00ea2f4030>

I know it gives this error because the "teacher" column does not exist in the Course, however I don't want it to exist in the Course because it already exists in the reputation tables.

Am I going about this the wrong way? How to I ensure that the reputation gets added to a specific course if I can't use this?

form_for @course

Do I have to do something like this? This feels like poor programming to me.

form_tag courses_path + course_name, :method => 'post'
Jeff Davenport
  • 2,624
  • 2
  • 13
  • 19

1 Answers1

1

You need to add a virtual attribute to your Course model like

attr_accessor :teacher

You may want to check this answer first

https://stackoverflow.com/a/3136485/522897

Community
  • 1
  • 1
Onur Kucukkece
  • 1,708
  • 1
  • 20
  • 46