0

I would like to create New Task button which will redirect to /users/:user_id/tasks/new
Routes:

  devise_for :users
  resources :users do
    resources :tasks, shallow: true
  end

Task Controller:

  def new
    @task = Task.new
  end

View:

<%= link_to "New Task", new_user_task_path(@user) %> 

but it gives me - No route matches {:action=>"new", :controller=>"tasks", :user_id=>nil} missing required keys: [:user_id] error.

Gregy
  • 340
  • 1
  • 6
  • 16

1 Answers1

0

Instead of having new_user_task_path(@user) you would like to have probably new_user_task_path(current_user). @user is nil in this case.

blelump
  • 3,233
  • 1
  • 16
  • 20
  • Thanks a lot. I have tried with current_user once and no idea why it didn't work, maybe restart of rails server was needed. – Gregy Nov 08 '14 at 20:49