Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
forms
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Jan 26, 2012
1 parent b686f0d commit 62fab07
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 49 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -6,4 +6,5 @@
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
14 changes: 13 additions & 1 deletion app/controllers/application_controller.rb
@@ -1,11 +1,23 @@
class ApplicationController < ActionController::Base
protect_from_forgery

before_filter :require_login

private

def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user

def require_login
unless logged_in?
flash[:error] = "You must be logged in to access this section"
redirect_to log_in_url # прерывает цикл запроса
end
end

def logged_in?
!!current_user
end

end
7 changes: 6 additions & 1 deletion app/controllers/stories_controller.rb
Expand Up @@ -42,7 +42,12 @@ def edit
# POST /stories
# POST /stories.json
def create
@story = Story.new(params[:story])
valid_params = params[:story]
responsible_user_id = params[:story][:responsible_user_id]
valid_params.delete(:responsible_user_id)
valid_params[:responsible_user] = User.find(responsible_user_id)

@story = @current_user.stories.new(valid_params)

respond_to do |format|
if @story.save
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
@@ -1,4 +1,6 @@
class UsersController < ApplicationController
skip_before_filter :require_login, :only => [:new, :create]

# GET /users
# GET /users.json
def index
Expand Down
55 changes: 37 additions & 18 deletions app/views/layouts/application.html.erb
@@ -1,17 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Auth Example</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body class="<%= params[:controller] %>">

<!-- Topbar
================================================== -->
<div class="topbar" data-scrollspy="scrollspy" >
<div class="topbar-inner">
<head>
<title>Simply task manager</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>


<style type="text/css">
body {
padding-top: 40px; /* 40px to make the container go all the way to the bottom of the topbar */
}
</style>

</head>
<body class="<%= params[:controller] %>">

<!-- Topbar
================================================== -->
<div class="topbar">
<div class="fill">
<div class="container">
<a class="brand" href="#">Simply task manager</a>
<ul class="nav">
Expand All @@ -30,11 +38,22 @@
</div>


<div id="container">
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
<%= yield %>
</div>
<div class="container">

<div class="row">
<div class="span16">
<% flash.each do |name, msg| %>
<div class="alert-message info" data-alert="alert">
<a class="close" href="#">&times;</a>
<%= content_tag :p, msg %>
</div>
<% end %>
</div>
</div>



<%= yield %>
</div>
</body>
</html>
7 changes: 2 additions & 5 deletions app/views/stories/_form.html.erb
Expand Up @@ -19,13 +19,10 @@
<%= f.label :body %><br />
<%= f.text_area :body %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>

<div class="field">
<%= f.label :responsible_user_id %><br />
<%= f.number_field :responsible_user_id %>
<%= f.select "responsible_user_id", User.all.collect {|p| [ p.name, p.id ] }, :include_blank => 'None' %>
</div>
<div class="actions">
<%= f.submit %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/stories/index.html.erb
Expand Up @@ -6,6 +6,7 @@
<th>Body</th>
<th>User</th>
<th>Responsible user</th>
<th>State</th>
<th></th>
<th></th>
<th></th>
Expand All @@ -15,8 +16,9 @@
<tr>
<td><%= story.title %></td>
<td><%= story.body %></td>
<td><%= story.user_id %></td>
<td><%= story.responsible_user_id %></td>
<td><%= story.user.name %></td>
<td><%= story.responsible_user.name %></td>
<td><%= story.state %></td>
<td><%= link_to 'Show', story %></td>
<td><%= link_to 'Edit', edit_story_path(story) %></td>
<td><%= link_to 'Destroy', story, :confirm => 'Are you sure?', :method => :delete %></td>
Expand Down
47 changes: 29 additions & 18 deletions app/views/users/_form.html.erb
Expand Up @@ -10,24 +10,35 @@
</ul>
</div>
<% end %>
<div class="row">
<div class="span16">
<div class="clearfix">
<%= f.label :name %><br />
<div class="input">
<%= f.text_field :name %>
</div>
</div>
<div class="clearfix">
<%= f.label :email %><br />
<div class="input">
<%= f.text_field :email %>
</div>
</div>
<div class="clearfix">
<%= f.label :password %><br />
<div class="input">
<%= f.password_field :password %>
</div>
</div>
<div class="clearfix">
<%= f.label :password_confirmation %><br />
<div class="input">
<%= f.password_field :password_confirmation %>
</div>
</div>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit %>
<%= f.submit %>
</div>
</div>

<% end %>
14 changes: 10 additions & 4 deletions app/views/users/new.html.erb
@@ -1,5 +1,11 @@
<h1>New user</h1>
<div class="content">
<div class="page-header">
<h1>New user</h1>
</div>
<div class="row">
<div class="span16">
<%= render 'form' %>
</div>
</div>
</div>

<%= render 'form' %>
<%= link_to 'Back', users_path %>

0 comments on commit 62fab07

Please sign in to comment.