Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created September 14, 2012 16:53
Show Gist options
  • Save telagraphic/3723210 to your computer and use it in GitHub Desktop.
Save telagraphic/3723210 to your computer and use it in GitHub Desktop.
<%= form_for([@day, @feed]) do |f| %>
<%= f.text_area :live_feed, :size => "34x13" %><br>
<%= f.submit %>
<% end %>
<br>
<%= link_to "Back", day_path(@day) %><br>
<h1>Status...</h1>
<%= render "feed_form" %>
<h1>Live Feed</h1>
<% @feeds.each do |f| %>
<ul>
<li><%= f.live_feed %></li>
</ul>
<% end %>
class FeedsController < ApplicationController
def index
@day = Day.find(params[:day_id])
@feed = @day.feeds.build # build association object
@feeds = @day.feeds.all # list all feed submits
end
def create
@day = Day.find(params[:day_id])
@feed = @day.feeds.build(params[:live_feed])
if @feed.save
redirect_to day_feeds_path(@day)
else
render "index"
end
end
end
class Day < ActiveRecord::Base
attr_accessible :sleep, :wake
has_one :habit, :dependent => :destroy
has_many :feeds, :dependent => :destroy
belongs_to :user
end
class Feed < ActiveRecord::Base
belongs_to :day
attr_accessible :live_feed
end
Life::Application.routes.draw do
devise_for :users do
resources :days
end
root :to => "Days#index"
resources :days do
resources :habits
end
resources :days do
resources :feeds
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment