Search code examples
ruby-on-railssimple-form

Undefined method error when using simple_form (newbie)


I've got the following simple_form:

= simple_form_for instance do |f|
  = f.input :update_resolution, collection: 1..10
  = f.button :submit

It throws the error:

undefined method `update_resolution' for #<Instance:0x007f0c07329640>

In instances_controller.rb I have:

  def update_resolution 
    render nothing: true, status: 200, content_type: 'text/html'
  end

And I'm not 100% sure what's best to put in routes.rb.

Goal: I'm trying make an auto-submitting dropdown to allow the user to run update_resolution with certain params.

Questions:

  1. Why does it throw this error & how can I fix it?
  2. What is the preferred routes.rb strategy?

Solution

  • This can be achieved with a model less simple_form. Look at the following code:

    <%= simple_form_for :user, url: users_path do |f| %>
      <%= f.input :name, as: :string %>
      ...
    <% end %>
    

    url: users_path can be changed to the action you want it to post to. In your case update_resolution_instance_path The action will take the params being passed to it and do whatever it needs to do.

    I am using something similar to be able to take data from fields and then send an email to the user entered email address.