Using form_with of rails5, I want to show current time text by clicking GET button. But text isn't updated.
Though I press the button,
Text isn't updated.
Text in response is updated.
users_controller.rb is following.
require 'date'
class UsersController < ApplicationController
def index
@message = Time.now.to_s
end
end
index.html.erb is following.
<div><%= @message %></div>
<%= form_with method: :get, url: users_path do |form| %>
<%= form.submit 'SUBMIT'%>
<% end %>
<%= link_to 'LINK', { :controller => :users, :action => :index } %>
Please, tell me how to update text by current time.
NOTE:
When press a link(rendered by link_to helper method), text is updated.
press link...
then text is updated.
why I can update text by link?
EDIT:
Server log when clicking the button is following.
Started GET "/users?utf8=%E2%9C%93&commit=SUBMIT" for 127.0.0.1 at 2018-08-17 19:13:32 +0900
Processing by UsersController#index as JS
Parameters: {"utf8"=>"✓", "commit"=>"SUBMIT"}
Rendering users/index.html.erb within layouts/application
Rendered users/index.html.erb within layouts/application (4.7ms)
Completed 200 OK in 153ms (Views: 112.5ms | ActiveRecord: 0.0ms)
Can you try the following?
<%= form_with method: :get, url: users_path, local: true do |form| %>
I noticed in your logs
Processing by UsersController#index as JS
which means that the form is submitted with format: :js
because form_with
now defaults to remote: true
as you could see HERE (you can't do remote: false
however, but instead use local: true
), unlike form_for
and form_tag
where remote: false
by default, but you specify remote: true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With