0

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?
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
cjm2671
  • 18,348
  • 31
  • 102
  • 161
  • Can you please show your model code? – Arslan Ali Jun 09 '15 at 07:21
  • update_resolution is your controller method which you are trying to call in view? – Vrushali Pawar Jun 09 '15 at 07:21
  • 3
    Inside a form you are trying to call **controller action**,... What the heck! :/ – Arup Rakshit Jun 09 '15 at 07:23
  • 1
    Your `f` is a model object, and you can call the methods which are defined inside the models as instance method on `f`... not the controller actions.. – Arup Rakshit Jun 09 '15 at 07:24
  • 1
    OP, before you move a single step, please read this - http://guides.rubyonrails.org/getting_started.html .. You will get the idea. – Arup Rakshit Jun 09 '15 at 07:25
  • from your controller action what you are trying to do? – Vrushali Pawar Jun 09 '15 at 07:25
  • maybe you are looking for a model less form. where your form does not perform any action on items on DB. if that is the case then something like this will be the way to go. http://stackoverflow.com/a/5181627/827770 – Qaiser Wali Jun 09 '15 at 07:26
  • 1
    @ArslanAli I am upset. :/ .. Why not some tutorials people try and then jump into the actual development.. :( – Arup Rakshit Jun 09 '15 at 07:29
  • 1
    @ArupRakshit I agree. – Arslan Ali Jun 09 '15 at 07:30
  • 1
    @ArslanAli Thanks Bro! for understanding. I didn't want to be _rude_, I just got shocked.. Myself also still _newbie_ in Rails. It is huge and full loaded with lots of useful features. I am still swimming at the corner of it.. – Arup Rakshit Jun 09 '15 at 07:32
  • The problem is, I can't pass any params into the model, hence I moved it into the controller. I also think the controller *is* the right place for this kind of action (it's not a saved attribute, just do something and quit). I'm not sure what to put where, and hence make the form work. – cjm2671 Jun 09 '15 at 07:36
  • @cjm2671 You can pass the `params` value to the model method, by calling the methods of model inside the controller and `params` as arguments to those methods.. – Arup Rakshit Jun 09 '15 at 07:40
  • OK, I understand, but how do I then call the controller method from the form? – cjm2671 Jun 09 '15 at 07:44
  • `form_for` is there to create input fields not anything else more.. I am not sure what you want to do ? – Arup Rakshit Jun 09 '15 at 07:57
  • Well I wanted a form generator rather than having to code html elements myself - that's what I was trying to avoid. – cjm2671 Jun 09 '15 at 07:59
  • @cjm2671 do look at the model less simple_form choice I mentioned in my previous comment. I am also posting it as an answer. – Qaiser Wali Jun 09 '15 at 15:46

1 Answers1

0

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.

Qaiser Wali
  • 358
  • 5
  • 21