搜索后,“提交”按钮不起作用

时间:2013-01-18 09:15:40

标签: javascript ajax ruby-on-rails-3

我一直在寻找解决方案,但这是不可能的。我希望它得到很好的解释。

我有一个小表单用户列表来更改数据库中的一个属性(该属性是要知道用户已经完成了登记)。

enter image description here

还有一位搜索者使用AJAX显示结果,以便不会重新加载所有页面。当我第一次加载页面时,浏览器呈现HTML并且Save按钮按预期工作。但是当我使用搜索器并且列表出现时(使用JS),提交按钮不起作用。在Mozilla中,Firefox什么都不做,在谷歌浏览器中我收到此错误:No route matches "user's profile route"。搜索者工作正常(显示正确的用户)。我使用Rails 3.0.1和Ruby 1.8.7

check_in.html.erb

这是搜索者和渲染调用

<%= form_tag({:controller => "admins", :action => "check_in"}, :id => "users_search", :method => "get", :html => {:autocomplete => "off"}) do %>
  <%= hidden_field_tag :selected_event_id, params[:selected_event_id] %>
  <p>
     <%= text_field_tag :search, params[:search] %>
     <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>    
<div id="check_in"><%= render :partial => 'check_in' %></div>

_check_in.html.erb

这是上面呈现的部分

  <%@event_user_infos.each do |user_info|subscription = Subscription.find(:first, :conditions => ["user_id = ? and event_id = ?", user_info.user_id, params[:selected_event_id]])%>
       <%= simple_form_for(subscription) do |f| %>
          <%= f.hidden_field :user_id %>  
          <%= f.hidden_field :event_id %>
          <tr>
          <td><%= link_to user_info.name, subscription %></td>
          <td><%= user_info.company %></td>
          <td><%= user_info.user.email %></td>
          <td><%= subscription.networkId %></td>
              <td><%= f.input :token, :input_html => { :size => 15, :maxlength => 15 }, :as => :integer, :label => false %></td>
              <td width='5px'>
                 <%= f.submit 'save' %>
              </td>
         </tr>
      <% end %>
 <% end %>

admins_controller.rb

我只放了代码的相关部分

def check_in
    event_id = params[:selected_event_id]
    if !event_id.nil?
      session[:event_id] = event_id      
      @event_user_infos = UserInfo.search(params[:search],event_id).order(sort_column + ' ' + sort_direction)
   end
end

check_in.js.erb

$('#check_in').html('<%= escape_javascript(render :partial => 'check_in') %>');

修改

我在部分表单中添加了条件:remote => remote选项(如果有搜索remote == true,如果不是remote == false),Google Chrome中的错误消失了,但它仍然存在没有(现在在两个浏览器中)。我还检查了HTML源代码,似乎没问题。

1 个答案:

答案 0 :(得分:0)

我终于设法解决了这个问题。我更改了<%= javascript_include_tag :defaults%>文件中<%= javascript_include_tag 'prototype'%>的{​​{1}}代码行,现在可以在两个浏览器中使用。

相关问题