diff --git a/Gemfile b/Gemfile index 852278f..18b7145 100644 --- a/Gemfile +++ b/Gemfile @@ -38,4 +38,3 @@ gem 'jquery-rails' # To use debugger gem 'ruby-debug' - diff --git a/Gemfile.lock b/Gemfile.lock index 2d6571a..d4da936 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,6 +74,7 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.0.3) + nifty-generators (0.4.6) orm_adapter (0.0.5) polyglot (0.3.2) rack (1.3.5) @@ -143,6 +144,7 @@ DEPENDENCIES inboxes! jquery-rails json + nifty-generators rails (= 3.1.1) ruby-debug sass-rails (~> 3.1.4) diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss deleted file mode 100644 index f0ddc68..0000000 --- a/app/assets/stylesheets/home.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the home controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffold.css b/app/assets/stylesheets/scaffold.css new file mode 100644 index 0000000..69854bb --- /dev/null +++ b/app/assets/stylesheets/scaffold.css @@ -0,0 +1,75 @@ +body { + background-color: #4B7399; + font-family: Verdana, Helvetica, Arial; + font-size: 14px; +} + +a img { + border: none; +} + +a { + color: #0000FF; +} + +.clear { + clear: both; + height: 0; + overflow: hidden; +} + +#container { + width: 75%; + margin: 0 auto; + background-color: #FFF; + padding: 20px 40px; + border: solid 1px black; + margin-top: 20px; +} + +#flash_notice, #flash_error, #flash_alert { + padding: 5px 8px; + margin: 10px 0; +} + +#flash_notice { + background-color: #CFC; + border: solid 1px #6C6; +} + +#flash_error, #flash_alert { + background-color: #FCC; + border: solid 1px #C66; +} + +.fieldWithErrors { + display: inline; +} + +.error_messages { + width: 400px; + border: 2px solid #CF0000; + padding: 0px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; + font-size: 12px; +} + +.error_messages h2 { + text-align: left; + font-weight: bold; + padding: 5px 10px; + font-size: 12px; + margin: 0; + background-color: #c00; + color: #fff; +} + +.error_messages p { + margin: 8px 10px; +} + +.error_messages ul { + margin: 0; +} diff --git a/app/helpers/error_messages_helper.rb b/app/helpers/error_messages_helper.rb new file mode 100644 index 0000000..a6b7ffc --- /dev/null +++ b/app/helpers/error_messages_helper.rb @@ -0,0 +1,23 @@ +module ErrorMessagesHelper + # Render error messages for the given objects. The :message and :header_message options are allowed. + def error_messages_for(*objects) + options = objects.extract_options! + options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields") + options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.") + messages = objects.compact.map { |o| o.errors.full_messages }.flatten + unless messages.empty? + content_tag(:div, :class => "error_messages") do + list_items = messages.map { |msg| content_tag(:li, msg) } + content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe) + end + end + end + + module FormBuilderAdditions + def error_messages(options = {}) + @template.error_messages_for(@object, options) + end + end +end + +ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb new file mode 100644 index 0000000..09fa349 --- /dev/null +++ b/app/helpers/layout_helper.rb @@ -0,0 +1,22 @@ +# These helper methods can be called in your template to set variables to be used in the layout +# This module should be included in all views globally, +# to do so you may need to add this line to your ApplicationController +# helper :layout +module LayoutHelper + def title(page_title, show_title = true) + content_for(:title) { h(page_title.to_s) } + @show_title = show_title + end + + def show_title? + @show_title + end + + def stylesheet(*args) + content_for(:head) { stylesheet_link_tag(*args) } + end + + def javascript(*args) + content_for(:head) { javascript_include_tag(*args) } + end +end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 0e2cd31..4db0d9d 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,5 +1,5 @@ %h1 - Home#index + Home %p Find me in app/views/home/index.html.erb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index edea9b5..7034d53 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,16 +1,19 @@ - - InboxesApp - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> - - -

<%= notice %>

-

<%= alert %>

- -<%= yield %> - - + + <%= content_for?(:title) ? yield(:title) : "Untitled" %> + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tag %> + <%= yield(:head) %> + + +
+ <% flash.each do |name, msg| %> + <%= content_tag :div, msg, :id => "flash_#{name}" %> + <% end %> + <%= content_tag :h1, yield(:title) if show_title? %> + <%= yield %> +
+ diff --git a/db/seeds.rb b/db/seeds.rb index d34dfa0..c99e6f9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,5 @@ # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Emanuel', :city => cities.first) +User.create(:name => 'Emanuel', :email => "emanuel@example.com", :password => "123456") +User.create(:name => 'Alex', :email => "alex@example.com", :password => "123456")