ruby - Basic dashboard to manage posts in rails -
I have a blog that plans for authentication and where users can create posts, I have created an original dashboard Where users will be able to manage their posts
This is my dashboard controller
before_action: authenticate_user! DF Index @Posts = Post.Fund (All :: Terms => ["user_id =?", @current_user]) This is my dashboard view
& lt;% @ posts.each do | Posted in | & Gt%; & Lt;% = post.content% & gt; & Lt;% end% & gt; This is my user model
is_im: post and my post model
related_to: user this is my schema. RB
create_table "posts", force: true do | T | t.text "content" t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" end But when I go to the dashboard I can not find any Post and when I can change my dashboard controller to
def index @ postsall = post.all end I'am get all the posts To do so someone can say where is my fault.
find (: all, : Terms = & gt; []) was demoted in Rail 3.2. Instead, try: def index @ posts = post.where (: user_id = & gt; current_user) expiration Also, make sure In the method that you are adding user_id to your controller:
def @ post = post.New (post_most) @ post.user_id = current_user empty code ends here
Comments
Post a Comment