我搜索了各种答案,但到目前为止,没有一个对我有用。所以这是我的表单,当我从Web视图提交表单时,它运行良好,但是在移动设备上,表单会自动执行GET调用而不是POST调用。 但是,当我删除目标::_blank时,它在移动设备上可以正常工作。但是,当我单击搜索按钮时更改URL时,我需要将用户重定向到新页面。
当前网址:http://localhost:4000/hotels/470?website_template_id=3
NewPage网址:http://localhost:4000//booking_widget/availability
尽管如此,相同的URL在Web上仍能正常工作。
<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>
我的路线定义为:
post 'booking_widget/availability' => 'booking_widget#availability', :as => 'booking_availability'
生成的错误消息是:
No route matches [GET] "/booking_widget/availability"
并且控制器动作是这样的:
class Widget::BookingWidgetController < ApplicationController
def availability
render("/website_templates/#{website_template_id}/bookings/booking_search_results" ,:layout => false)
end
end
移动请求日志:
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)
Web请求日志:
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)