我想在 Post 表中显示所有帖子,说 id=5 ......
控制器
user_controller.rb
class UsersController < ApplicationController
# other methods are also present...
def profile
uid=session[:userid] #session contains userid,it is stored in uid....Eg:5
@post=Post.find_by_userid(uid) #Display all posts with userid=5 in Post table.
end
end
看法
profile.html.erb
<h1>In Profile</h1>
<%=session[:test]%>
<% @post.each do |p|%>
<%= p.title%>
<%= p.body%>
<%= p.tag%>
<%end%>
当我执行时,我收到一个错误,例如....
请帮我修复错误......谢谢。