So I’m trying to search through a model through a form. Basically my end goal is to be able to assign a value a “user” in my User model if this search manages to obtain at least 1 search result, which will only happen if both the Username and Password match on the form for the Organization.
The controller:
class OrganizationsController < ApplicationController
def join
@organization = Organization.find_by_username_and_password(params[:organization])
end
end
The view:
<div class="row">
<div class="span6">
<%= form_for(@organization) do |f| %>
<%= f.label :username %>
<%= f.text_field :username %>
<%= f.label :password %>
<%= f.password_field :password %>
<br />
<%= f.submit "Join!", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
I just can’t get this to work. What am I doing wrong?
Any help/recommendations would be really appreciated!
You can use dynamic finder methods and provide respective attribute value to search.
e.g
we are searching email and pasword,in finder method email come first so first parameter should be email’s value and second for password
interesting you can use any combination of your model’s attributes to search
Awesome Rails 🙂