1

I have searched through various answers but none have worked for me so far. So here is my form which is working fine when I do a form submission from web view, but on mobile the form automatically does a GET call instead of POST call. However when I remove, target: :_blank, it works fine on mobile. But I need to redirect user to a new page as I change URLs when search button is clicked.

Current url: http://localhost:4000/hotels/470?website_template_id=3

NewPage url: http://localhost:4000//booking_widget/availability

The same URLs are working fine on web though.

<div class="booking-widget">
  <%= form_tag("#{Settings.host_url}/booking_widget/availability", method: :post , target: :_blank , id: :booking_search_form,:class => "form-inline reservation-horizontal clearfix")%>
    <div class="booking-area">
      <div class="booking-values">
        <h4>CHECK IN</h4>
        <input type="hidden" id="check-in" name="start_date" value="" />
        <p class="check-in"> <span><span></p>
        <div id="from"></div>
      </div>
      <div class="booking-values">
        <h4>CHECK OUT</h4>
        <input type="hidden" id="check-out" name="end_date" value="" />
        <p class="check-out"> <span><span></p>
        <div id="to"></div>
      </div>
      <div class="booking-values">
        <input type="hidden" id="rooms" name="rooms" value="1" />
        <h4>ROOMS</h4>
        <p class="rooms">1</p>
        <div class="dropdown">
          <ul id="booking_room_select">
            <%(1..@max_no_of_rooms).each do |num|%>
            <li data-value="<%=num%>"><%=num%></li>
            <%end%>
          </ul>
        </div>
      </div>
      <div class="booking-values">
        <input type="hidden" id="adults" name="adults" value="1" />
        <h4>ADULTS</h4>
        <p class="adults-click">1</p>
        <div class="adults-children">
          <div class="room-set">
            <div class="room-header">
              ROOM 1
            </div>
            <div class="room-changer">
              <div class="changers adults">
                <p>ADULTS</p>
                <input id="single_room_no_of_adults" class="form-control numbers-count" type="number" value="1" min="1" max="<%=@max_no_of_adults%>" disabled />
              </div>
              <div class="changers children">
                <p>CHILDREN</p>
                <input id="single_room_no_of_children" class="form-control numbers-count" type="number" value="0" min="0" max="<%=@max_no_of_children%>" disabled />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="booking-values">
        <input type="hidden" id="children" name="children" value="0" />
        <h4>CHILDREN</h4>
        <p class="children-click">0</p>
      </div>
      <div class="booking-values hidden">
        <input type="hidden" name="hotel_id" value="<%=@hotel.id%>"/>
        <input type="hidden" name="currency" value="INR"/>
        <input type="hidden" name="party" id="party" value=""/>
        <input type="hidden" id="website_template_id" name="website_template_id" value="3" />
      </div>
    </div>
    <div class="booking-cta">
      <button id="booking-widget-submit" formmethod="post" type="submit">BOOK NOW</button>
    </div>
  </form>
  <div class="clearfix"></div>
</div>

My route is defined as:

post 'booking_widget/availability' => 'booking_widget#availability', :as => 'booking_availability'

The error message generated is:

No route matches [GET] "/booking_widget/availability"

And controller action is as such:

class Widget::BookingWidgetController < ApplicationController
  def availability
    render("/website_templates/#{website_template_id}/bookings/booking_search_results" ,:layout => false)
  end
end

Logs for Mobile request:

Rendered /Users/name/.rvm/gems/ruby-2.0.0-p648/gems/actionpack-3.2.18/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.5ms)

Logs for Web request:

Processing by Widget::BookingWidgetController#availability as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "start_date"=>"20-6-2018", "end_date"=>"21-6-2018", "rooms"=>"1", "adults"=>"1", "children"=>"0", "hotel_id"=>"470", "currency"=>"INR", "party"=>"[{\"adults\":\"1\",\"children\":[]}]", "website_template_id"=>"3"}
Rendered website_templates/3/hotel_website/_header.html.erb (31.2ms)
Rendered website_templates/3/hotel_website/_booking-widget-search-results.html.erb (44.2ms)
Rendered website_templates/3/hotel_website/_footer.html.erb (0.8ms)
Rendered website_templates/3/hotel_website/_scripts.html.erb (4.0ms)
Rendered website_templates/3/bookings/booking_search_results.html.erb (147.0ms)
Completed 200 OK in 6826.3ms (Views: 150.0ms | ActiveRecord: 882.9ms)
Tanmay Jain
  • 311
  • 3
  • 8
  • Can you show the server logs for requests from both desktop and mobile? – Jagdeep Singh Jun 20 '18 at 09:38
  • That's another problem, no logs are generated when the call is done from mobile. – Tanmay Jain Jun 20 '18 at 09:44
  • Not sure what `target: :_blank` has got to do with this? You said you need to redirect the user, not open a new tab. – Tom Lord Jun 20 '18 at 10:41
  • My bad, I need the search button to open a new tab. As the new tab has to be timed out after few minutes of inactivity. – Tanmay Jain Jun 20 '18 at 10:45
  • You've also tagged this as `javascript`, but there's no JS code in your question? I haven't encountered this issue before, but a quick google reveals that [others have](https://github.com/electron/electron/issues/2816). Perhaps this is a bug in whichever mobile device/browser you're using? (You didn't specify.) Have you tried any alternate solutions, such as [triggering a new window on submit](https://stackoverflow.com/a/35421291/1954610) with JavaScript? – Tom Lord Jun 20 '18 at 11:08
  • Yes, I have tried various methods and none seem to work for me. The problem is occuring on both iOS and android (iPhone X, iPhone 6s, one plus 6), I have tested it on various browsers like Chrome, UC Browser, Safari all have same issue. – Tanmay Jain Jun 20 '18 at 12:46

0 Answers0