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.
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.