Pingu
Pingu

Reputation: 11

How to display something after a user input (submit) ? > HAML + RubyOnRails

So im quite new to Ruby. I already have some HTML/HAML experience, now I want to do a simple Website with this: A input field and a submit button.

If the user input is < 10 it should display some picture, if its > 10, it should display a other picture. This is what I've done so far:

enter image description here

What should I do now to proccess the user input ? I just can't figure out.

Upvotes: 0

Views: 377

Answers (2)

Zoran J
Zoran J

Reputation: 52

In this case, where you are not doing any server side processing, you should use JavaScript.

Just check value of the input field and do your logic from there.

$('form').on('submit',function(){
  if ($('#Input1').val() < 10) {
    $("#my_image").attr("src","first.jpg");
  } 
  else {
    $("#my_image").attr("src","second.jpg");
  }
}) 

Upvotes: 1

Adnan Devops
Adnan Devops

Reputation: 503

Your form syntax is incorrect, it missing the controller action. It should be like this:

= form_for controller_method, :html => { :class => "form-horizontal" }

Upvotes: 0

Related Questions