在下面的一段代碼中(當然在視圖中)我有<td><%= post.full_hsh %></td>
正確顯示了字段post.full_hsh
的值,但是url_for
給出了一個錯誤:No route matches {:controller=>"posts", :action=>"edit", :id=>nil}
。Rails:url_to scope
爲什麼post.full_hsh
連續修正並且nil
在下面的行中?由於
<% @posts.each do |post| %>
<tr>
<td><%= truncate post.body, :length => 100, :separator => ' ' %>...</td>
<td><%= post.created_at %></td>
<td><%= post.full_hsh %></td>
<td><%= url_for :controller => 'posts', :action => 'edit', :id => post.full_hsh %></td>
</tr>
<% end %>
編輯:
我routes.rb
文件:
get "admin/index"
root :to => 'home#index'
#access posts via /posts/ab123c or /p/ab123c
resources :posts, :path => 'p', :except => [:new, :index, :delete]
resources :posts, :except => [:new, :index, :delete]
match '/p/:id/delete' => 'posts#delete', :as => 'posts_delete'
match '/admin' => 'admin#index'
可您發佈'routes.rb'文件? –
你能否告訴我們'post.full_hsh'可能是什麼樣子? –
這是一個簡單的sha1哈希:'9e60d55edf826483672497b22f9da794571b1275' – pistacchio