Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # models/user.rb
- class User < ActiveRecord::Base
- has_secure_password
- attr_accessible :email, :password, :password_confirmation, :profile_attributes, :group_ids
- has_one :profile, :inverse_of => :user
- accepts_nested_attributes_for :profile
- end
- # models/profile.rb
- class Profile < ActiveRecord::Base
- attr_accessible :first_name, :last_name, :phone_fix, :phone_mobile, :user_id, :zip_code
- belongs_to :user, :inverse_of => :profile
- end
- # controllers/users_controller.rb
- class UsersController < ApplicationController
- def index
- @q = User.joins(:profile).search(params[:q])
- @users = @q.result.paginate(:per_page =>10, :page => params[:page])
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @users }
- end
- end
- def search
- @q = User.joins(:profile).search(params[:q])
- @users = @q.result.paginate(:per_page => 10, :page => params[:page])
- render "index"
- end
- end
- # views/users/index.html.erb (search form only)
- <%= search_form_for @q, url: search_users_path, method: 'post', id: 'users-search-form' do |f| %>
- <%= f.text_field :profile_last_name_or_profile_first_name %>
- <%= f.submit %>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement