未定义的方法“stringify_keys”错误使用 Rails 3
Undefined method `stringify_keys' error using Rails 3
当我设置根据下拉值搜索数据的表单时出现以下错误。
错误:
NoMethodError in Users#index
Showing C:/Site/searchtest/app/views/users/index.html.erb where line #4 raised:
undefined method `stringify_keys' for nil:NilClass
Extracted source (around line #4):
1: <h1>Listing users</h1>
2: <%= form_tag users_path, :method => 'get' do %>
3: <p>
4: <%= text_field_tag(:search,options_for_select([['subhrajyotipradhan@gmail.com','subhrajyotipradhan@gmail.com'],['subhrajyoti.pradhan@oditeksolutions.com','subhrajyoti.pradhan@oditeksolutions.com'],['w5call.w5rtc@gmail.com','w5call.w5rtc@gmail.com']],selected: "Select your email"), params[:search]) %>
5: <%= submit_tag "Search", :name => nil %>
6: </p>
7: <% end %>
我的目标是当用户 select 从下拉列表中选择值时应该过滤 accordingly.Please 检查我下面的代码并尝试帮助我使其正确。
views/users/index.html.erb
<h1>Listing users</h1>
<%= form_tag users_path, :method => 'get' do %>
<p>
<%= text_field_tag(:search,options_for_select([['subhrajyotipradhan@gmail.com','subhrajyotipradhan@gmail.com'],['subhrajyoti.pradhan@oditeksolutions.com','subhrajyoti.pradhan@oditeksolutions.com'],['w5call.w5rtc@gmail.com','w5call.w5rtc@gmail.com']],selected: "Select your email"), params[:search]) %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Content</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.content %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New User', new_user_path %>
我想用 will_paginate gem functionality.Please 帮帮我。
您不能使用 selected: "Select your email"
。它必须是您的选项之一,因此 selected: 'subhrajyotipradhan@gmail.com'
或 selected: subhrajyoti.pradhan@oditeksolutions.com
或 selected: 'w5call.w5rtc@gmail.com'
你可以试试这个。希望对您有所帮助
select_tag "search", options_for_select(['subhrajyotipradhan@gmail.com', 'subhrajyotipradhan@gmail.com'], 'subhrajyotipradhan@gmail.com')
当我设置根据下拉值搜索数据的表单时出现以下错误。
错误:
NoMethodError in Users#index
Showing C:/Site/searchtest/app/views/users/index.html.erb where line #4 raised:
undefined method `stringify_keys' for nil:NilClass
Extracted source (around line #4):
1: <h1>Listing users</h1>
2: <%= form_tag users_path, :method => 'get' do %>
3: <p>
4: <%= text_field_tag(:search,options_for_select([['subhrajyotipradhan@gmail.com','subhrajyotipradhan@gmail.com'],['subhrajyoti.pradhan@oditeksolutions.com','subhrajyoti.pradhan@oditeksolutions.com'],['w5call.w5rtc@gmail.com','w5call.w5rtc@gmail.com']],selected: "Select your email"), params[:search]) %>
5: <%= submit_tag "Search", :name => nil %>
6: </p>
7: <% end %>
我的目标是当用户 select 从下拉列表中选择值时应该过滤 accordingly.Please 检查我下面的代码并尝试帮助我使其正确。
views/users/index.html.erb
<h1>Listing users</h1>
<%= form_tag users_path, :method => 'get' do %>
<p>
<%= text_field_tag(:search,options_for_select([['subhrajyotipradhan@gmail.com','subhrajyotipradhan@gmail.com'],['subhrajyoti.pradhan@oditeksolutions.com','subhrajyoti.pradhan@oditeksolutions.com'],['w5call.w5rtc@gmail.com','w5call.w5rtc@gmail.com']],selected: "Select your email"), params[:search]) %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Content</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.content %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New User', new_user_path %>
我想用 will_paginate gem functionality.Please 帮帮我。
您不能使用 selected: "Select your email"
。它必须是您的选项之一,因此 selected: 'subhrajyotipradhan@gmail.com'
或 selected: subhrajyoti.pradhan@oditeksolutions.com
或 selected: 'w5call.w5rtc@gmail.com'
你可以试试这个。希望对您有所帮助
select_tag "search", options_for_select(['subhrajyotipradhan@gmail.com', 'subhrajyotipradhan@gmail.com'], 'subhrajyotipradhan@gmail.com')