Skip to content

Commit

Permalink
Merge pull request #65 from jasonpettus/views
Browse files Browse the repository at this point in the history
Added ability to create subscriptions on 'edit sections' page
  • Loading branch information
withtwoemms committed Jul 21, 2015
2 parents d930825 + 38d75d6 commit cf30a2f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
25 changes: 25 additions & 0 deletions app/assets/stylesheets/evening-edition.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ p {
float: right;
}

.vertical-center {
position: absolute;
top: 33%;
right: 0.5em;
}

.cl-r {
clear: right;
}
Expand Down Expand Up @@ -127,6 +133,10 @@ p {
margin: auto;
}

.center-box {
margin: auto;
}

.section_box {
text-align: center;
margin: auto;
Expand All @@ -145,6 +155,21 @@ p {
text-align: left;
}

.w-50 {
width: 50%;
}

.pd-4 {
padding: 0 4em 0 4em;
}

.pd-2 {
padding: 0 2em 0 2em;
}

.gray-box {
position: relative;
background-color: LightGray;
vertical-align: bottom;
padding: 0.5em;
}
2 changes: 2 additions & 0 deletions app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def index
@sections = current_user.sections
@section = Section.new
@page_name = "Edit Sections"
@subscription = @section.subscriptions.new
# @feed = Feed.new
end

def show
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
class SubscriptionsController < ApplicationController
def new
def new
@subscription = Subscription.new
end

def create
p params
@section = Section.find_by(id: params[:section_id])
@subscription = Subscription.create(params[subscription_params], section: @section)

@subscription = Subscription.create(subscription_params)
@subscription.update_attributes(section: @section, feed: Feed.first_or_create(feed_url: params['subscription']['feed']))
if @subscription.valid?
redirect_to edit_section( @section )
redirect_to section_path(@section)
end
end

Expand All @@ -18,6 +19,6 @@ def delete

private
def subscription_params
params.require(:subscription).permit(:feed_url, :name)
params.require(:subscription).permit(:name)
end
end
58 changes: 45 additions & 13 deletions app/views/sections/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--4-col-phone round mdl-cell--8-col center pd-4">
<div class="section_box"><p>
<div class="mdl-cell mdl-cell--4-col-phone round mdl-cell--8-col center-box pd-4">
<p>
<%= form_for @section do |f| %>
<%= f.text_field :title, class: 'list-left', placeholder: 'Section name' %>
<%= f.submit value: 'Add Section' %>
<%= f.text_field :title, class: 'list-left w-50', placeholder: 'Section name' %>
<%= f.submit value: 'Add Section', class: 'inline fl-r' %>
<% end %>
</p></div>
</p>

<% @sections.each do |section| %>
<p class="list-left">
<%= form_tag("/sections/#{ section.id }", method: :delete, class: 'inline fl-r') do %>
<%= submit_tag 'Delete' %>
<% end %>
<%= form_tag(edit_section_path( section ), method: :get, class: 'inline fl-r') do %>
<%= submit_tag 'Rename' %>
<% end %>
<div class="list-left gray-box">
<span class="vertical-center">
<%= form_tag("/sections/#{ section.id }", method: :delete, class: 'inline') do %>
<%= submit_tag 'Delete' %>
<% end %>
<%= form_tag(edit_section_path( section ), method: :get, class: 'inline') do %>
<%= submit_tag 'Rename' %>
<% end %>
</span>

<span class="mdl-typography--display-2 inline">
<%= link_to "#{ section.title }", section_subscriptions_path( section ) %>
</span>
</p>
</div>


<div class="pd-2">
<p>
<%= form_for @subscription, url: "/sections/#{section.id}/subscriptions/#{@subscription.id}" do |f| %>
<%= f.text_field :name, class: 'list-left w-50', placeholder: 'Subscription Name' %>
<%= f.text_field :feed, class: 'list-left w-50', placeholder: 'RSS feed' %>
<%= f.submit value: 'Add Feed', class: 'inline fl-r' %>
</p>
<% end %>
<% section.subscriptions.each do |subscription| %>
<p class="list-left">
<span class="vertical-center">
<%= form_tag("/subscriptions/#{ subscription.id }", method: :delete, class: 'inline') do %>
<%= submit_tag 'Delete' %>
<% end %>
<%= form_tag(edit_section_subscription_path( section, subscription ), method: :get, class: 'inline') do %>
<%= submit_tag 'Rename' %>
<% end %>
</span>

<span class="mdl-typography--title inline">
<%= link_to subscription.name, section_subscription_path( section, subscription ) %>
</span>
</p>
<% end %>
</div>

<% end %>
</div>
</div>

0 comments on commit cf30a2f

Please sign in to comment.