0
你好,我是一個新的ROR,我有路由問題。我的路線是 http://localhost:3000/keys/pass.9
,我想成爲像http://localhost:3000/keys/9/pass
Ruby on Rails路線
看我的路線:
resources :keys , only: [:new, :show, :create, :edit, :update, :index] do
collection do
delete 'destroy_multiple'
get 'pass'
end
末
控制器:
class KeysController < ApplicationController
def pass
Key.find(params[:id]).update_attribute(:passwrod,SecureRandom.urlsafe_base64)
respond_to do |format|
format.html { redirect_to books_path }
format.json { head :no_content }
flash[:success] = "Profile updated"
end
end
和視圖:
<div class="center hero-unit">
<h1>Listing keys</h1>
<%= form_tag destroy_multiple_keys_path, method: :delete do %>
<table>
<thead>
<tr>
<th></th>
<th>Url</th>
<th>Username</th>
<th>Passwrod</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<div>
<% for key in @keys %>
<% if key.book.name == @book %>
<tr>
<td><%= check_box_tag "key_ids[]", key.id %></td>
<td><%=key.url %></td>
<td><%=key.username %></td>
<td><%=key.passwrod %></td>
<td><%=key.category %></td>
<td><%= link_to 'Edit',edit_key_path(key) %></td>
<td> <%= link_to 'Change password', pass_keys_path(key) %> </td>
</tr>
<% end %>
<% end %>
<tr>
<td> <input type="button" value="check all" onclick="$(this.form).getInputs('checkbox').each(function (elem) {elem.checked = true;});" /> </td>
</tr>
</div>
<%= submit_tag "Delete selected" %>
<% end %>
<%= link_to 'New Key', new_key_path %>
<%= link_to 'Back', books_path %>
</div>
,現在我得到這個錯誤:
沒有ID
'成員做 拿到「通行證」 end' 對於要一個成員的路線,而不是一個集合中的路線 –
@ user3438570使用成員.. – sp1rs