Question

Ruby on Rails 3.2.13
Redmine: 2.3.1.stable
Browser: Chrome, Firefox, latest versions

Problem

I'm trying to submit a start and end date via date picker and reload the current page with the chosen values. Based on this values a query is executed and the data is displayed in an HTML table. We thought that this approach might be easier than fiddling with JavaScript. We thought wrong...

The problem is, although the POST request is correctly executed (debugged all!) and the new HTML code is correctly submitted (Firebug shows it!) the new content is NEVER displayed, no matter what we do in the show function!

Viewer (show.html.erb): (simplified, has two date pickers, a submit button and a paragraph text)

<%= form_tag("/report_show", remote: true, :id => 'report_form', :name => 'report_form') do %>
<fieldset class="attributes">
<div>
    <p>
        <label for='start_date'><%= l("from") %></label>
        <%= text_field_tag 'start_date', @report_start_date.strftime("%Y-%m-%d"), :size => 10 %><%= calendar_for('start_date') %>
    </p>
    <p>
        <label for='end_date'><%= l("to") %></label>
        <%= text_field_tag 'end_date', @report_end_date.strftime("%Y-%m-%d"), :size => 10 %><%= calendar_for('end_date') %>
    </p>
</div>
</fieldset>


<p class="buttons">
    <button type="submit" id="report_submit"><%= l(:button_apply)%></button>
</p>

<%end%>

<p>end date: <%= @report_end_date %></p>

As you can see, the only modifiable information I left in is an HTML paragraph which simply displays the @report_end_date. However, it never changes when clicking on the submit button.

Controller (report_controller.rb):

class ReportController < ApplicationController
  unloadable

# redirect user to current month selection
def index
    @user = User.current
    @report_start_date = Date.civil(Date.today.year, Date.today.month, 1)
    @report_end_date = Date.civil(Date.today.year, Date.today.month, -1)
    render "show"
end

# show the time report for the selected time period
def show
    @user = User.current
    @report_start_date = Date.strptime(params[:start_date], "%Y-%m-%d")
    @report_end_date = Date.strptime(params[:end_date], "%Y-%m-%d")
end

end

Routes:

post 'report_show', :to => 'report#show'

Testing

Loading the page via default URL. Function index is executed and show.html is rendered. Dates display first and last of the current month.

After an end date is chosen, the submit button is clicked. The page still displays the same content although it has changed as shown below:

POST parameters: (as displayed in Firebug)

Parametersapplication/x-www-form-urlencoded
authenticity_token  U0golNARia5Jwq9kd2J49OfDMYHxVP/a2H/u5RYGaYQ=
end_date    2014-04-14
start_date  2014-04-01
utf8    ✓

Response HTML code: (as displayed in Firebug)

...
<p>end date: 2014-04-14</p>
...

Why is the new content not shown in any browser??

Was it helpful?

Solution

Solution:

Seems that you need to set remote: of the form tag to false in order to disable Ajax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top