Commit a081b91
Changed files (7)
app
config
db
app/controllers/links_controller.rb
@@ -0,0 +1,10 @@
+class LinksController < ApplicationController
+ def index
+ @links = Link.all
+ end
+
+ def create
+ raise StandardError
+ redirect_to links_path
+ end
+end
app/controllers/needs_controller.rb
@@ -9,10 +9,6 @@ class NeedsController < ApplicationController
@need = Need.find(params[:id])
end
- def new
- @need = Need.new
- end
-
def create
@need = current_user.needs.create(params[:need])
current_user.tag(@need, :with => params[:need_tags], :on => :tags)
app/models/link.rb
@@ -0,0 +1,12 @@
+class Link < ActiveRecord::Base
+ attr_accessible :description, :heading, :url, :image_url, :user_id, :author, :author_url
+ validates :url, :presence => true
+ belongs_to :user
+ acts_as_taggable
+
+ default_scope order("created_at DESC")
+
+ def to_param
+ "#{id}-#{heading.gsub(/[^a-z0-9]+/i, '-')}"
+ end
+end
app/views/links/index.html.erb
@@ -0,0 +1,42 @@
+
+<% content_for :javascript do %>
+<script src="http://cdn.embed.ly/jquery.embedly-3.0.5.min.js" type="text/javascript"></script>
+<script src="http://cdn.embed.ly/jquery.preview-0.3.2.min.js" type="text/javascript"></script>
+<link rel="stylesheet" href="http://cdn.embed.ly/jquery.preview-0.3.2.css" />
+<script>
+$('#url').preview({ key:'<%= ENV['EMBEDLY_KEY'] %>' });
+$('form').on('submit', function(){
+ $(this).addInputs($('#url').data('preview'));
+ return true;
+});
+</script>
+<% end %>
+
+<div class="row">
+ <div class="span12">
+ <%= form_for Link.new, :url => links_path, :method => :post, :html => { :class => "form-horizontal" } do |f| %>
+ <input id="url" type="text" name="url"/>
+ <%= f.submit :add, :class => "btn" %>
+ <div class="selector-wrapper"></div>
+ <% end %>
+ </div>
+</div>
+
+<div class="row">
+ <div class="span12">
+ <table class="table">
+ <tr>
+ <th></th>
+ <th></th>
+ <th>Need</th>
+ <th>Tags</th>
+ <th></th>
+ </tr>
+ <% @links.each do |link| %>
+ <tr>
+ <td><%= link.url %></td>
+ </tr>
+ <% end %>
+ </table>
+ </div>
+</div>
config/routes.rb
@@ -5,8 +5,9 @@ Yycrebuild::Application.routes.draw do
devise_for :users
- resources :needs
- resources :neighbourhoods
+ resources :needs, :only => [:index, :show, :create]
+ resources :neighbourhoods, :only => [:index]
resources :resources
+ resources :links, :only => [:index, :create], :path => :l
resources :tags, :only => [:show], :path => :t
end
db/migrate/20130623155032_create_links.rb
@@ -0,0 +1,14 @@
+class CreateLinks < ActiveRecord::Migration
+ def change
+ create_table :links do |t|
+ t.string :url
+ t.string :image_url
+ t.string :heading
+ t.text :description
+ t.string :author
+ t.string :author_url
+ t.integer :user_id
+ t.timestamps
+ end
+ end
+end
db/schema.rb
@@ -46,6 +46,18 @@ ActiveRecord::Schema.define(:version => 20130624022039) do
add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
+ create_table "links", :force => true do |t|
+ t.string "url"
+ t.string "image_url"
+ t.string "heading"
+ t.text "description"
+ t.string "author"
+ t.string "author_url"
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "needs", :force => true do |t|
t.text "description"
t.integer "user_id"