Erin Walker
Erin Walker

Reputation: 739

NoMethodError in Static_pages#home

I'm getting a no method error in my Static_pages#home:

undefined method `exists?' for Registry

 The little code I'm using it in is:

 <% if user_signed_in? && current_user.registry.exists? %>

 <%= link_to "Show My Registry", current_user.registry %>

 <% else %>

 <%= link_to "Create a new registry", new_registry_path %>

 <% end %>

Should I add something to the controller for home?

Thanks in advance.

Upvotes: 0

Views: 264

Answers (2)

Erin Walker
Erin Walker

Reputation: 739

In the end this worked:

<% if user_signed_in? && Registry.exists?(current_user.registry) %>

Upvotes: 0

Anil
Anil

Reputation: 3919

The exists? method is a class method. You have to either do:

Registry.exists?  # Is there any registery?

or specify the id for the Registry:

Registry.exist?(current_user.registry_id)

Here is some reference:

http://apidock.com/rails/ActiveRecord/Base/exists%3F/class

Good luck!

Upvotes: 1

Related Questions