<td><%= post.full_hsh %></td>
코드의 다음 코드에서 post.full_hsh
필드의 값을 올바르게 표시하지만 url_for
은 오류 : No route matches {:controller=>"posts", :action=>"edit", :id=>nil}
을 제공합니다.레일 : 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' 파일을 게시 할 수,
싶어? –:id => post
대신 당신은 객체 자체를 기반으로 URL을 생성 할'post.full_hsh'가 어떻게 생겼는지 아이디어를 줄 수 있습니까? –
그것은 평범한 sha1 해시입니다 : '9e60d55edf826483672497b22f9da794571b1275' – pistacchio