Last active
December 21, 2015 16:18
-
-
Save tummykung/6332546 to your computer and use it in GitHub Desktop.
I have a problem posting values filled in the form to pass model validation. The password is not getting passed (validation presence fails). I use the Single Table Inheritance pattern, and I am confused why this problem occurs. Any help is appreciated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdminsController < UsersController | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess | |
utf8: ✓ | |
_method: put | |
authenticity_token: YkJcV0/sdFk8k7ANNW1uJy/6Adzl7lylfGnVy4vw1UE= | |
mentor: !ruby/hash:ActiveSupport::HashWithIndifferentAccess | |
name: Test Test | |
email: test@test.com | |
description: sdfsdf | |
college: ssdfsdf | |
affiliation: sdfsdf | |
password: sdfsdf | |
password_confirmation: sdfsdfsdf | |
commit: Save changes | |
action: update | |
controller: mentors | |
id: '8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% provide(:title, "Edit user") %> | |
<h1>Update your profile</h1> | |
<div class="row"> | |
<div class="span6 offset3"> | |
<%= form_for(@user) do |f| %> | |
<%= render 'shared/error_messages', object: f.object %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<%= f.label :email %> | |
<%= f.text_field :email %> | |
<%= f.label :password %> | |
<%= f.password_field :password %> | |
<%= f.label :password_confirmation, "Confirm Password" %> | |
<%= f.password_field :password_confirmation %> | |
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %> | |
<% end %> | |
<%= gravatar_for @user %> | |
<a href="http://gravatar.com/emails">change</a> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The form contains 3 errors. | |
* Password can't be blank | |
* Password is too short (minimum is 6 characters) | |
* Password confirmation can't be blank | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Processing by AdminsController#update as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"YkJcV0/sdFk8k7ANNW1uJy/6Adzl7lylfGnVy4vw1UE=", "admin"=>{"name"=>"Test2", "email"=>"test@test2.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Save changes", "id"=>"2"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rake routes | |
following_user GET /users/:id/following(.:format) users#following | |
followers_user GET /users/:id/followers(.:format) users#followers | |
users GET /users(.:format) users#index | |
POST /users(.:format) users#create | |
new_user GET /users/new(.:format) users#new | |
edit_user GET /users/:id/edit(.:format) users#edit | |
user GET /users/:id(.:format) users#show | |
PUT /users/:id(.:format) users#update | |
DELETE /users/:id(.:format) users#destroy | |
sessions POST /sessions(.:format) sessions#create | |
new_session GET /sessions/new(.:format) sessions#new | |
session DELETE /sessions/:id(.:format) sessions#destroy | |
microposts POST /microposts(.:format) microposts#create | |
micropost DELETE /microposts/:id(.:format) microposts#destroy | |
relationships POST /relationships(.:format) relationships#create | |
relationship DELETE /relationships/:id(.:format) relationships#destroy | |
mentors GET /mentors(.:format) mentors#index | |
POST /mentors(.:format) mentors#create | |
new_mentor GET /mentors/new(.:format) mentors#new | |
edit_mentor GET /mentors/:id/edit(.:format) mentors#edit | |
mentor GET /mentors/:id(.:format) mentors#show | |
PUT /mentors/:id(.:format) mentors#update | |
DELETE /mentors/:id(.:format) mentors#destroy | |
mentees GET /mentees(.:format) mentees#index | |
POST /mentees(.:format) mentees#create | |
new_mentee GET /mentees/new(.:format) mentees#new | |
edit_mentee GET /mentees/:id/edit(.:format) mentees#edit | |
mentee GET /mentees/:id(.:format) mentees#show | |
PUT /mentees/:id(.:format) mentees#update | |
DELETE /mentees/:id(.:format) mentees#destroy | |
static_pages_home GET /static_pages/home(.:format) static_pages#home | |
static_pages_help GET /static_pages/help(.:format) static_pages#help | |
users_new GET /users/new(.:format) users#new | |
root / static_pages#home | |
help /help(.:format) static_pages#help | |
network /network(.:format) static_pages#network | |
search /search(.:format) static_pages#search | |
share /share(.:format) static_pages#share | |
play /play(.:format) static_pages#play | |
about /about(.:format) static_pages#about | |
contact /contact(.:format) static_pages#contact | |
signup /signup(.:format) users#new | |
signin /signin(.:format) sessions#new | |
signout /signout(.:format) sessions#destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MenteesController < UsersController | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MentorsController < UsersController | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tryloop::Application.routes.draw do | |
resources :users do | |
member do | |
get :following, :followers | |
end | |
end | |
resources :sessions, only: [:new, :create, :destroy] | |
resources :microposts, only: [:create, :destroy] | |
resources :relationships, only: [:create, :destroy] | |
resources :mentors | |
resources :mentees | |
resources :admins | |
get "static_pages/home" | |
get "static_pages/help" | |
get "users/new" | |
root to: 'static_pages#home' | |
match '/help', to: 'static_pages#help' | |
match '/network', to: 'static_pages#network' | |
match '/search', to: 'static_pages#search' | |
match '/share', to: 'static_pages#share' | |
match '/play', to: 'static_pages#play' | |
match '/about', to: 'static_pages#about' | |
match '/contact', to: 'static_pages#contact' | |
match '/signup', to: 'users#new' | |
match '/signin', to: 'sessions#new' | |
match '/signout', to: 'sessions#destroy' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
attr_accessible :name, :email, :password, :password_confirmation, :type | |
attr_accessible :description, :interest, :xptag_time, :goal, :photo_id, :title, :zip | |
has_secure_password | |
has_many :microposts, dependent: :destroy | |
has_many :relationships, foreign_key: "follower_id", dependent: :destroy | |
has_many :followed_users, through: :relationships, source: :followed | |
has_many :reverse_relationships, foreign_key: "followed_id", | |
class_name: "Relationship", | |
dependent: :destroy | |
has_many :followers, through: :reverse_relationships, source: :follower | |
before_save { |user| user.email = email.downcase } | |
before_save :create_remember_token | |
validates :name, presence: true, length: { maximum: 50 } | |
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates :email, presence: true, | |
format: { with: VALID_EMAIL_REGEX }, | |
uniqueness: { case_sensitive: false } | |
validates :password, presence: true, length: { minimum: 6 } | |
validates :password_confirmation, presence: true | |
class Mentor < User | |
attr_accessible :affiliation, :xptag, :college | |
end | |
class Mentee < User | |
attr_accessible :college_1, :college_2, :college_3, :school | |
end | |
class Admin < User | |
attr_accessible :affiliation, :xptag, :college | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers] | |
before_filter :correct_user, only: [:edit, :update] | |
before_filter :admin_user, only: :destroy | |
def show | |
@user = User.find(params[:id]) | |
@microposts = @user.microposts.paginate(page: params[:page]) | |
end | |
def index | |
@users = User.paginate(page: params[:page]) | |
end | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
sign_in @user | |
flash[:success] = "Welcome to Test!" | |
redirect_to network_path | |
else | |
render 'new' | |
end | |
end | |
def edit | |
end | |
def update | |
if @user.update_attributes(params[:user]) | |
flash[:success] = "Profile updated" | |
sign_in @user | |
redirect_to @user | |
else | |
render 'edit' | |
end | |
end | |
def destroy | |
User.find(params[:id]).destroy | |
flash[:success] = "User destroyed." | |
redirect_to users_url | |
end | |
private | |
def correct_user | |
@user = User.find(params[:id]) | |
redirect_to(root_path) unless current_user?(@user) | |
end | |
def admin_user | |
redirect_to(root_url) unless current_user.admin? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment