Fixed up new post form

added a cancel button
This commit is contained in:
2013-01-21 19:10:48 -05:00
parent c75da12d94
commit 1887288f5b
7 changed files with 32 additions and 38 deletions

View File

@@ -90,23 +90,6 @@ table a { font-weight:bold; }
margin: 0 auto; margin: 0 auto;
} }
.demo_notice {
display:block;
clear:both;
padding:10px 10px 10px 36px;
-webkit-border-radius:3px;
-moz-border-radius:3px;
border-radius:3px;
border:1px solid;
color:#646464;
background-position:10px 12px;
background-repeat:no-repeat;
margin:10px 0;
background-color: #cee6f2;
border: solid 1px #058dc7;
background-image:url('/assets/icon_notification_information.png');
}
#flash_notice, #flash_error, #flash_alert { #flash_notice, #flash_error, #flash_alert {
display:block; display:block;
clear:both; clear:both;

View File

@@ -1,6 +1,6 @@
/* Modules /* Modules
--------------------------------------------------------------------------------------------------*/ --------------------------------------------------------------------------------------------------*/
.module { border:1px solid #e2e2e2; margin:.8em 0; background-color:#fff; overflow:auto; } .module { border:1px solid #e2e2e2; margin:.8em 0; background-color:#fff; }
.module_controls { padding:.8em; } .module_controls { padding:.8em; }
.module_header { color:#fff; padding:.7em .7em .7em 1.4em; background-color:#000; } .module_header { color:#fff; padding:.7em .7em .7em 1.4em; background-color:#000; }
.module_header a { color:#fff; } .module_header a { color:#fff; }

View File

@@ -2,6 +2,8 @@ class PostsController < ApplicationController
load_and_authorize_resource :topic load_and_authorize_resource :topic
load_and_authorize_resource :post, :through => :topic, :shallow => true load_and_authorize_resource :post, :through => :topic, :shallow => true
before_filter :check_for_cancel#, :only[:create, :update]
def new def new
if params[:quote] if params[:quote]
quote_post = Post.find(params[:quote]) quote_post = Post.find(params[:quote])
@@ -12,6 +14,7 @@ class PostsController < ApplicationController
end end
def create def create
check_for_cancel
@post.user ||= current_user @post.user ||= current_user
if @post.save if @post.save
flash[:notice] = "Post was successfully created." flash[:notice] = "Post was successfully created."
@@ -42,4 +45,10 @@ class PostsController < ApplicationController
end end
end end
def check_for_cancel
if params[:commit] == 'cancel'
redirect_to topic_path(@post.topic)
end
end
end end

View File

@@ -1,3 +1,8 @@
module ApplicationHelper module ApplicationHelper
def cancel_link
return link_to 'Cancel', request.env["HTTP_REFERER"],
:confirm => 'Are you sure? Any changes will be lost.'
end
end end

View File

@@ -8,19 +8,19 @@
<%= form_for("user", :as => resource_name, :url => registration_path("user")) do |f| %> <%= form_for("user", :as => resource_name, :url => registration_path("user")) do |f| %>
<p> <p>
Username: <br /> Username: <br />
<%= f.text_field :username, :style => "font-size:2.2em", :autocomplete => "off" %><br /> <%= f.text_field :username, :autocomplete => "off" %><br />
</p> </p>
<p> <p>
Email Address: <br /> Email Address: <br />
<%= f.text_field :email, :style => "font-size:2.2em", :autocomplete => "off" %><br /> <%= f.text_field :email, :autocomplete => "off" %><br />
</p> </p>
<p> <p>
Password:<br /> Password:<br />
<%= f.password_field :password, :style => "font-size:2.2em", :autocomplete => "off" %><br /> <%= f.password_field :password, :autocomplete => "off" %><br />
</p> </p>
<p> <p>
Confirm Password:<br /> Confirm Password:<br />
<%= f.password_field :password_confirmation, :style => "font-size:2.2em", :autocomplete => "off" %><br /> <%= f.password_field :password_confirmation, :autocomplete => "off" %><br />
</p> </p>
<p><%= f.submit "Sign up" %></p> <p><%= f.submit "Sign up" %></p>
<% end %> <% end %>

View File

@@ -24,8 +24,8 @@
</div> </div>
<div style="float:right; width:45%; height:195px; padding-left:30px; border-left:1px solid #e2e2e2;"> <div style="float:right; width:45%; height:195px; padding-left:30px; border-left:1px solid #e2e2e2;">
<%= form_for("user", :url => user_session_path) do |f| %> <%= form_for("user", :url => user_session_path) do |f| %>
<p><%= f.text_field :username , :value => "username", :style => "font-size:2.2em;" %></p> <p><%= f.text_field :username , :value => "username" %></p>
<p><%= f.password_field :password, :value => "password", :style => "font-size:2.2em" %></p> <p><%= f.password_field :password, :value => "password" %></p>
<%= f.submit 'Sign in' %> <%= f.submit 'Sign in' %>
<% end %> <% end %>
</div> </div>

View File

@@ -1,25 +1,22 @@
<div class="module"> <div class="module">
<div class="module_header"><%= action_name.humanize %> Post</div> <div class="module_header">
Re: <%= @post.topic.title %>
</div>
<div class="module_subheader smaller"></div> <div class="module_subheader smaller"></div>
<div class="module_body"> <div class="module_body">
<%= form_for [@topic, @post] do |f| %> <%= form_for [@topic, @post] do |f| %>
<% if @post.errors.any? %> <% if @post.errors.any? %>
<% flash.now[:error] = @post.errors.full_messages.join(', and ') %> <% flash.now[:error] = @post.errors.full_messages.join(', and ') %>
<% end %> <% end %>
<div class="fieldset"> <%= f.label :body %>
<span class="label indent smaller"> <%= f.text_area :body, :width => "80%", :rows => 15 %>
<%= f.label :body %><br />
<small>(Required)</small>
</span>
<span class="input indent smaller"><%= f.text_area :body, :cols => 60, :rows => 15 %></span>
<div class="clear"></div>
</div>
</div> </div>
<div class="module_footer"> <div class="module_footer">
<div class="fieldset"> <span class="input">
<span class="input"><%= f.submit "submit" %> or <%= link_to "cancel", topic_path(@post.topic) %></span> <%= f.submit "Submit", :class =>"btn btn-primary"%>
<%= button_tag "Cancel", :confirm => 'Are you sure? Any changes will be lost.', :class => 'btn', :type => 'submit', :name => 'commit', :value => 'cancel' %>
</span>
<div class="clear"></div> <div class="clear"></div>
</div>
</div> </div>
<% end %> <% end %>
</div> </div>