Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7719645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:28:02+00:00 2026-06-01T03:28:02+00:00

I followed RailsCasts authentication from scratch (http://railscasts.com/episodes/250-authentication-from-scratch-revised) using the bcrypt-ruby gem and have the

  • 0

I followed RailsCasts authentication from scratch (http://railscasts.com/episodes/250-authentication-from-scratch-revised) using the bcrypt-ruby gem and have the best in place gem in the app from another RailsCasts episode (http://railscasts.com/episodes/302-in-place-editing).

I have users, sessions, and tasks models. After the user logs in the application routes the user to tasks#index. Rather than having all tasks display, I want only the tasks that belong to the current_user in tasks#index to display.

My model associations look like this:
Subscription: has_many :users,
Tasks: belongs_to :user,
User: has_many :tasks and belongs_to :subscription

Users table has e-mail and password columns. Tasks table has content column.

The simple authentication from scratch creates a helper method in the application.rb file that I am having difficulty accessing in my tasks controller:

def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user

My tasks#controller index action looks like..

@tasks = Task.order("position")
@task = Task.new

end`

My tasks#index looks like this:

`
<% @tasks.each do |task| %>
<li id="task_<%= task.id %>"><%= best_in_place task, :content %>
<%= link_to raw("&times;"), task, method: :delete, remote: true  %>
<span class="handle">&mdash;</span>
</li>
<% end %>`

`

<%= form_for(Task.new) do |f| %>
<%= f.text_field  :content, :placeholder => "Add a new task here" %>
<% end %>

`

How can I restrict tasks to only the tasks created by the current user?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:28:04+00:00Added an answer on June 1, 2026 at 3:28 am

    Because the User has many Tasks, in your tasks controller you can use the below to restrict the tasks to the current users as per below…

    @tasks = @current_user.tasks.order("position")
    @task = Task.new(:user => @current_user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently implemented Authlogic to my project for authentication. I followed http://railscasts.com/episodes/160-authlogic and had
I've just followed the Railscast tutorial: http://railscasts.com/episodes/262-trees-with-ancestry Is it possible to paginate results from
I followed the rails cast of omniauth to create authentication for twitter ( http://railscasts.com/episodes/235-omniauth-part-1?view=comments
I have followed the instructions on http://railscasts.com/episodes/147-sortable-lists for creating a sortable list. The list
I followed the Railcast #253 http://railscasts.com/episodes/253-carrierwave-file-uploads and works great. But then I implemented it
I am specifically intertested in #270. You can see it here: http://railscasts.com/episodes/270-authentication-in-rails-3-1 I've downloaded
I followed Ryan Bates Omniauth Part1 railscats http://railscasts.com/episodes/235-omniauth-part-1 . I put twitter and Facebook
I followed Railscasts #235 and #236 to setup creating user authentications with omniauth. http://railscasts.com/episodes/235-omniauth-part-1
I followed the tutorial http://railscasts.com/episodes/253-carrierwave-file-uploads?view=asciicast and I've got my nested form setup with the
I followed the instructions in Railscasts #197 http://railscasts.com/episodes/197-nested-model-form-part-2 about how to add links that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.