Permalink
Browse files

+destroy, admin

  • Loading branch information...
1 parent 5129c6a commit eeb526897f3099826b4fe6b7cf9ceda9f11e1c0c @DarTSeNSe committed Dec 9, 2011
@@ -3,7 +3,7 @@
}
body {
- background: #bebebe;
+ background: #cccccc;
}
header {
@@ -87,7 +87,7 @@ a.signup_button {
text-align: center;
width: 190px;
color: #fff;
- background: #006400;
+ background: #00cc33;
font-size: 150%;
font-weight: bold;
padding: 20px;
@@ -128,7 +128,7 @@ td.sidebar {
width: 30%;
padding: 1em;
vertical-align: top;
- background: #ffc;
+ background: #ffcccc;
}
.profile img.gravatar {
@@ -13,7 +13,7 @@ def create
render 'new'
else
sign_in user
- redirect_to user
+ redirect_back_or user
end
end
@@ -1,12 +1,9 @@
class UsersController < ApplicationController
-before_filter :authenticate, :only => [:edit, :update]
-before_filter :correct_user, :only => [:edit, :update]
-before_filter :authenticate, :only => [:index, :edit, :update]
+ before_filter :authenticate, :only => [:index, :edit, :update, :destroy]
+ before_filter :correct_user, :only => [:edit, :update]
+ before_filter :admin_user, :only => :destroy
+ before_filter :signedin, :only => [:new, :create]
- def index
- @title = "All users"
- @users = User.all
- end
def show
@user = User.find(params[:id])
@@ -19,15 +16,14 @@ def new
end
def create
- user = User.authenticate(params[:session][:email],
- params[:session][:password])
- if user.nil?
- flash.now[:error] = "Invalid email/password combination."
- @title = "Sign in"
- render 'new'
+ @user = User.new(params[:user])
+ if @user.save
+ sign_in @user
+ flash[:success] = "Welcome to the SimTrans!"
+ redirect_to @user
else
- sign_in user
- redirect_back_or user
+ @title = "Sign up"
+ render 'new'
end
end
@@ -51,6 +47,12 @@ def index
@users = User.paginate(:page => params[:page])
end
+ def destroy
+ User.find(params[:id]).destroy
+ flash[:success] = "User destroyed."
+ redirect_to users_path
+ end
+
private
def authenticate
@@ -62,4 +64,13 @@ def correct_user
redirect_to(root_path) unless current_user?(@user)
end
+ def admin_user
+ redirect_to(root_path) unless current_user.admin?
+ end
+
+ def signedin
+ redirect_to(root_path) if signed_in?
+ end
+
+
end
@@ -3,8 +3,8 @@
<ul>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact", contact_path %></li>
- <li><a href="http://news.railstutorial.org/">News</a></li>
- <li><a href="http://www.railstutorial.org/">Rails Tutorial</a></li>
+ <li><a href="http://news.google.com.ua/">News</a></li>
+ <li><a href="http://translate.google.com.ua/">Google translate</a></li>
</ul>
</nav>
</footer>
@@ -1,7 +1,4 @@
<h1>About Us</h1>
<p>
- <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
- is a project to make a book and screencasts to teach web development
- with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This
- is the sample application for the tutorial.
+ Translation service using Ruby on Rails v3.1.1
</p>
@@ -1,5 +1,4 @@
<h1>Contact</h1>
<p>
- Contact Ruby on Rails Tutorial about the sample app at the
- <a href="http://railstutorial.org/feedback">feedback page</a>.
+ Contact us by email - sense8life@gmail.com
</p>
@@ -1,7 +1,4 @@
<h1>Help</h1>
<p>
- Get help on Ruby on Rails Tutorial at the
- <a href="http://railstutorial.org/help">Rails Tutorial help page</a>.
- To get help on this sample app, see the
- <a href="http://railstutorial.org/book">Rails Tutorial book</a>.
+ Get <a href="http://scholar.google.com.ua/">help page</a>.
</p>
@@ -1,4 +1,8 @@
<li>
<%= gravatar_for user, :size => 30 %>
<%= link_to user.name, user %>
+ <% if current_user.admin? %>
+ | <%= link_to "delete", user, :method => :delete, :confirm => "Are You sure?",
+ :title => "Delete #{user.name}" %>
+ <% end %>
</li>
@@ -25,5 +25,5 @@
<div>
<%= gravatar_for @user %>
- <a href="http://gravatar.com/emails">change</a>
+ <a href="http://gravatar.com/emails" target="_blank">change</a>
</div>
@@ -0,0 +1,5 @@
+class AddAdminToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :admin, :boolean, :default => false
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111208142559) do
+ActiveRecord::Schema.define(:version => 20111209090431) do
create_table "users", :force => true do |t|
t.string "name"
@@ -20,6 +20,7 @@
t.datetime "updated_at"
t.string "encrypted_password"
t.string "salt"
+ t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
@@ -2,13 +2,15 @@ namespace :db do
desc "Fill database with sample data"
task :populate => :environment do
Rake::Task['db:reset'].invoke
- User.create!(:name => "Sense",
+ admin = User.create!(:name => "Sense",
:email => "sense8life@gmail.com",
:password => "0334818",
:password_confirmation => "0334818")
+ admin.toggle!(:admin)
+
99.times do |n|
name = Faker::Name.name
- email = "example-#{n+1}@railstutorial.org"
+ email = "example-#{n+1}@rails.org"
password = "password"
User.create!(:name => name,
:email => email,
Binary file not shown.
Binary file not shown.
View
@@ -4,10 +4,10 @@
before(:each) do
@attr = {
- :name => "Example User",
- :email => "user@example.com",
- :password => "foobar",
- :password_confirmation => "foobar"
+ :name => "Alex Sense",
+ :email => "sense@example.com",
+ :password => "example",
+ :password_confirmation => "example"
}
end

0 comments on commit eeb5268

Please sign in to comment.