2011-08-17 4 views
0

사용자 로그인 용으로 authlogic을 사용하고 있습니다. 일단 로그인하면 해당 사용자가 게시물을 추가 할 수 있기를 바랍니다. 어떤 이유로 나는 계속 "ID없이 사용자를 찾을 수 없습니다"라는 메시지가 계속 나타납니다.authlogic 및 posts for current_user

posts controller 
def create 
    @user = User.find(params[:user_id]) 
    @post = @user.posts.create(params[:post]) 
    redirect_to current_user_path(@current_user) 
end 

show page 
    <% @user.posts.each do |post| %> 
<tr> 
    <td><%= post.postName %></td> 
    <td><%= post.body %></td> 
    <td><%= link_to 'Show', post %></td> 
    <td><%= link_to 'Edit', edit_post_path(post) %></td> 
    <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>  </td> 
</tr> 
<% end %> 
</table> 

<br /> 

<h2>Add a Post:</h2> 
<%= form_for([@current_user, @user.posts.build]) do |f| %> 

    <div class="field"> 
    <%= f.label :body %><br /> 
    <%= f.text_area :body %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

나는 그것이 현재 사용자와 함께 할 수있는 뭔가가 알고 있지만, 나는이 작업을 얻을 수 없습니다 아래에 내 코드입니다! 어떤 도움이라도 대단히 감사합니다!

+0

일반적으로 authlogic은 "@current_user"가 아닌 "current_user"를 사용합니다 ... 메소드 호출이 아닌 인스턴스 변수로 사용자 정의 했습니까? –

+0

current_user가 오류를 반환합니다. URL에 사용자 ID를 사용하는 대신 내 게시물 모델로 라우팅하는 것 같습니다. – user893447

답변

0

첫째, 당신은, 당신이 @user = User.find(params[:user_id])을하고있는 current_user하지 @current_user

둘째를 사용해야하지만, 당신이 당신의 PARAMS에서 :user_id 같은 뭔가를 기대하는 이유는 이해가 안 돼요. 그렇기 때문에 "ID없는 사용자를 찾을 수 없습니다"오류가 발생합니다.

관련 문제