ruby - How to execute a rails action when html button is clicked? -



ruby - How to execute a rails action when html button is clicked? -

i trying clean array when html button clicked. have controller:

class infocontroller < applicationcontroller $names = {} def show render :print end def @name = params[:myinfo][:name] @number = params[:myinfo][:number] $names[@name] = @number render :test end def clean $names = {} end def add together end end

how go executing clean action when button within form clicked?

<h1>info print</h1> <%= form_for :myinfo |a| %> <%= a.label :name %> <%= a.text_field :name %><br> <%= a.label :number%> <%= a.text_field :number%><br> <%= a.submit %> <%end%> <form> <input type="button" onclick=""> </form> <%= $names.each |key, val|%> <%=key%> &nbsp <%=val%> <%end%>

you can write this:

<form> <%= link_to "clean", clean_path, :class => 'btn btn-primary'%> # can add together btn class if using bootstarp </form>

routes.rb:

get 'clean' => "info#clean"

ruby-on-rails ruby html5

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -