I am new to rails and regular expressions. I am trying to make an application in which Users can register with one of two types of email address: user@a.edu or user@b.edu. I am making a page that shows all users that are not the type of the current user. For example, jason@a.edu were logged in, the page would display all users of type b. If lauren@b.edu were logged in, the page would display all users of type a. I am trying to use regular expressions to know what type of user is logged in based on the email address and dynamically generate the page when the user clicks the link. I have created this method in the model:
def other_schools
if /.+@a\.edu/.match(current_user.email)
User.where(email != /.+@a\.edu/)
else
render :text => 'NOT WORKING', :status => :unauthorized
end
end
Here is the controller:
def index
#authorize! :index, :static_pages
@users = current_user.other_schools
end
Here is the view that displays each user:
<% @users.each do |user| %>
<li class="span3">
<div class="thumbnail" style="background: white;">
<%= image_tag "idea.jpeg" %>
<h3><%= user.role %></h3>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<a class="btn btn-primary">View</a>
</div>
</li>
<% end %>
The view simply loops through the @user object. When I try to load the page, I am told that there is an undefined local variable or method `current_user'. How do I fix this?