Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Worked on custom views and methods

  • Loading branch information...
commit 2ae7fec9feae4bab3e4459700089828c06c161c6 1 parent 8aff57a
@cpursley authored
View
11 app/controllers/dreams_controller.rb
@@ -5,7 +5,7 @@ class DreamsController < ApplicationController
# GET /dreams
# GET /dreams.json
def index
- @dreams = Dream.where(:state => '1') # public's view - all published articles
+ @dreams = Dream.where(:state => '1') # published view
respond_to do |format|
format.html # index.html.erb
@@ -13,11 +13,12 @@ def index
end
end
- def my
- @dreams = Dream.where(:state => ['0', '1']) # user's view - private and published articles
+ def mydreams
+ @mydreams = Dream.where(:state => ['0', '1']) # published view
+
respond_to do |format|
- format.html { render 'index' }
- format.json { render json: @dreams }
+ format.html # index.html.erb
+ format.json { render json: @mydreams }
end
end
View
72 app/views/dreams/_form.html.erb
@@ -11,51 +11,41 @@
</div>
<% end %>
+ <% if @dream.state < 1 %>
+ <div class="field">
+ <label for="dream_title">Title</label><br />
+ <%= f.text_field :title, :size => "100%", :class => "fullwidth" %>
+ </div>
+ <div class="field">
+ <label for="dream_teaser">Teaser</label><br />
+ <%= f.text_area :teaser, :size => "100%x5", :class => "fullwidth" %>
+ </div>
+
+ <% else %>
+
+ <div class="field">
+ <label for="dream_title">Title</label><br />
+ <%= f.text_field :title, :size => "100%", :class => "fullwidth" %>
+ </div>
+ <div class="field">
+ <label for="dream_teaser">Teaser </label><br />
+ <%= f.text_area :teaser, :size => "100%x5", :class => "fullwidth" %>
+ </div>
+ <% end %>
+
<div class="field">
- <%= f.label :user_id %><br />
- <%= f.number_field :user_id %>
- </div>
- <div class="field">
- <%= f.label :title %><br />
- <%= f.text_field :title %>
- </div>
- <div class="field">
- <%= f.label :teaser %><br />
- <%= f.text_area :teaser %>
- </div>
- <div class="field">
- <%= f.label :body %><br />
- <%= f.text_area :body %>
- </div>
- <div class="field">
- <%= f.label :version %><br />
- <%= f.text_field :version %>
- </div>
- <div class="field">
- <%= f.label :changelog %><br />
- <%= f.text_area :changelog %>
- </div>
- <div class="field">
- <%= f.label :message %><br />
- <%= f.text_field :message %>
- </div>
- <div class="field">
- <%= f.label :freezebody %><br />
- <%= f.text_area :freezebody %>
- </div>
- <div class="field">
- <%= f.label :state %><br />
- <%= f.number_field :state %>
- </div>
- <div class="field">
- <%= f.label :submitted %><br />
- <%= f.date_select :submitted %>
+ <label for="dream_body">Your dream</label><br />
+ <%= f.text_area :body, :size => "100%x40", :class => "fullwidth" %>
</div>
<div class="field">
- <%= f.label :accepted %><br />
- <%= f.date_select :accepted %>
+ <label for="dream_body">Changelog of this dream</label><br />
+ <%= f.text_area :changelog, :size => "100%x10", :class => "fullwidth" %>
</div>
+
<div class="actions">
<%= f.submit %>
+ <%= link_to 'View this dream', @dream %>
+ <%= link_to 'Return to my dreams', mydreams_dreams_path %>
</div>
-<% end %>
+
+<% end %>
View
2  app/views/dreams/edit.html.erb
@@ -4,3 +4,5 @@
<%= link_to 'Show', @dream %> |
<%= link_to 'Back', dreams_path %>
+
+
View
48 app/views/dreams/mydreams.html.erb
@@ -0,0 +1,48 @@
+<h2>Manage your Dreams</h2>
+
+<p><%= link_to 'Record a new dream', new_dream_path %></p>
+
+<section id="mydream">
+
+ <% if !@mydreams.empty? %>
+
+ <% @mydreams.each do |dream| %>
+
+ <dream class="mydream">
+
+ <div class="title"><%= dream.title %></div>
+ <div class="created">
+ Created / Last updated: <%= dream.created_at.strftime("%B %d, %Y") %> / <%= dream.updated_at.strftime("%B %d, %Y") %>
+ </div>
+
+ <!-- states: 0...private - 1...published -->
+
+ <% if dream.state == 0 %>
+ <div class="state">Current status: Private (visible via direct link)</div>
+ <% end%>
+
+ <% if dream.state == 1 %>
+ <div class="state">Current status: Published (<%= dream.submitted.strftime("%B %d, %Y") %>)</div>
+ <% end %>
+
+ <div class="actions">
+ <span class="show"><%= link_to 'View', dream %></span>
+ <span class="edit"><%= link_to 'Edit', edit_dream_path(dream) %></span>
+ <% if (dream.state == 0) or (dream.state == 2) %>
+ <span><%= link_to "Publish", "#" %></span>
+ <span class="delete"><%= link_to 'Delete', dream, :confirm => 'Are you sure?', :method => :delete %></span>
+ <% end %>
+ <% if dream.state == 1 %>
+ <span><%= link_to "Unpublish", "#" %></span>
+ <span class="delete"><%= link_to 'Delete', dream, :confirm => 'Are you sure?', :method => :delete %></span>
+ <% end %>
+ </div>
+
+ </dream>
+ <% end %>
+
+ <% else %>
+ <p>You have not recorded any dreams yet. Start to contribute: <%= link_to 'New Dream', new_dream_path %> %></p>
+ <% end %>
+
+</section>
View
6 app/views/layouts/_header.html.erb
@@ -4,13 +4,13 @@
<%= link_to "Lucidly: A dream journal", '/', id: "logo" %>
<nav>
<ul class="nav pull-right">
- <li><%= link_to "About", about_dreams_path %></li>
<li><%= link_to "Dreams", root_path %></li>
- <li><%= link_to "My Dreams", my_dreams_path %></li>
+ <li><%= link_to "My Dreams", mydreams_dreams_path %></li>
<% if user_signed_in? %>
<li><%= link_to "My Profile", edit_user_registration_path %></li>
<li><%= link_to "Sign out", destroy_user_session_path %></li>
- <% else %>
+ <% else %>
+ <li><%= link_to "About", about_dreams_path %></li>
<li><%= link_to "Sign up", new_user_registration_path %></li>
<li><%= link_to "Sign in", new_user_session_path %></li>
<% end %>
View
6 config/routes.rb
@@ -4,10 +4,12 @@
resources :dreams do
collection do
get 'about'
- get 'my'
- end
+ get 'all'
+ get 'mydreams'
+ end
end
+
root :to => "dreams#index"
# The priority is based upon order of creation:
Please sign in to comment.
Something went wrong with that request. Please try again.