0
我使用authlogic为用户登录,一旦他们这样做,我希望他们能够添加帖子。出于某种原因,我不断收到“无法找到没有ID的用户”。下面是我的代码:authlogic和当前用户的帖子
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