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 %>
나는 그것이 현재 사용자와 함께 할 수있는 뭔가가 알고 있지만, 나는이 작업을 얻을 수 없습니다 아래에 내 코드입니다! 어떤 도움이라도 대단히 감사합니다!
일반적으로 authlogic은 "@current_user"가 아닌 "current_user"를 사용합니다 ... 메소드 호출이 아닌 인스턴스 변수로 사용자 정의 했습니까? –
current_user가 오류를 반환합니다. URL에 사용자 ID를 사용하는 대신 내 게시물 모델로 라우팅하는 것 같습니다. – user893447