2011-11-23 4 views
0

<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' 
+0

당신은 당신의'routes.rb' 파일을 게시 할 수, :id => post 대신 당신은 객체 자체를 기반으로 URL을 생성 할

싶어? –

+0

'post.full_hsh'가 어떻게 생겼는지 아이디어를 줄 수 있습니까? –

+0

그것은 평범한 sha1 해시입니다 : '9e60d55edf826483672497b22f9da794571b1275' – pistacchio

답변

0

post.full_hshpost 반대의 속성입니다. 당신은 아마이 경우 post에서가 아닌 객체의 속성에 (post.full_hsh는)

+0

안녕하세요. 아뇨, 죄송합니다. 게시물 모델의 full_hsh 속성을 기반으로 맞춤 링크를 생성해야합니다. – pistacchio