Skip to content

Commit

Permalink
working forms, database, model, controller
Browse files Browse the repository at this point in the history
  • Loading branch information
codelitt committed May 8, 2012
1 parent e7cd372 commit 7a587b0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -6,7 +6,8 @@ def new
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "Post save message"
flash[:success] = "POST save message"
redirect_to '/success'
else
render 'new'
end
Expand Down
6 changes: 4 additions & 2 deletions app/models/user.rb
@@ -1,10 +1,12 @@
class User < ActiveRecord::Base
attr_accessible :email
attr_accessible :email, :usertype

before_save { |user| user.email = email.downcase }

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 :type, :presence => true
validates :usertype, :presence => true
end

#fans have a :type = 1, artists with :type = 2
3 changes: 3 additions & 0 deletions app/views/static/success.html.erb
@@ -0,0 +1,3 @@
<% provide(:title, "Thank you!") %>

<p>Success!</p>
3 changes: 2 additions & 1 deletion app/views/users/_artist_form.html.erb
@@ -1,4 +1,5 @@
<%= form_for(@user, :type => "1") do |f| %>
<%= form_for @user do |f| %>
<%= f.text_field :email, :placeholder => "Enter your email" %>
<%= f.hidden_field :usertype, :value => "2" %>
<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>
3 changes: 2 additions & 1 deletion app/views/users/_fan_form.html.erb
@@ -1,4 +1,5 @@
<%= form_for(@user, :type => "2") do |f| %>
<%= form_for @user do |f| %>
<%= f.text_field :email, :placeholder => "Enter your email" %>
<%= f.hidden_field :usertype, :value => "1" %>
<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>
5 changes: 3 additions & 2 deletions app/views/users/new.html.erb
@@ -1,4 +1,5 @@
<% provide(:title, "Sign up for beta access") %>
Fan?
<%= render 'users/fan_form' %>
<%= render 'users/artist_form' %>
Artist?
<%= render 'users/artist_form' %>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -4,6 +4,7 @@
resources :users

root :to => "users#new"
match 'success' => 'static#success'

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20120503034727_add_type_to_users.rb
@@ -1,6 +1,6 @@
class AddTypeToUsers < ActiveRecord::Migration
def change
add_column :users, :type, :string
add_index :users, :type
add_column :users, :usertype, :integer
add_index :users, :usertype
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Expand Up @@ -17,10 +17,10 @@
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "type"
t.string "usertype"
end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["type"], :name => "index_users_on_type"
add_index "users", ["usertype"], :name => "index_users_on_type"

end

0 comments on commit 7a587b0

Please sign in to comment.