I put@user = User.find(params[:id]) into the content_controller but I get the error "Couldn't find User without an ID".
This error means that params[:id] = nil
, i.e., you are not passing id
in the params hash when redirecting the user to content page
.
Possible Solutions:
With
Devise
you get a helper method calledcurrent_user
which returns an instance of currently logged in user. So, you could directly usecurrent_user
to access the attributes of currently logged in user. For example:To access
name
andemail
fields of currently logged in user, all you need to do iscurrent_user.name current_user.email
In
routes.rb
, pass theid
of the currently logged in user via the route ofcontent
page as below:## Add :id dynamic segment to your content page route get "content/:id", :to => "contents#action_name", :as => "content_page"
Since, I don't have the route details, you would need to modify the above route as per your requirement.
Next, when redirecting the user to
content
page aftersign up
just pass the currently logged in user as below inApplicationController
method namedafter_sign_up_path_for
(You need to override this Devise method if you want to redirect the user to a different route than the defaultroot path
):def after_sign_up_path_for(resource) content_page_path(resource) ## Provide the path and pass resource to it end