Commit 6cbfb2b
Changed files (6)
app
db
app/controllers/links_controller.rb
@@ -1,10 +1,12 @@
class LinksController < ApplicationController
+ before_filter :authenticate_user!, :except => [:index]
+
def index
@links = Link.all
end
def create
- raise StandardError
+ @link = current_user.links.create(:url => CGI.unescape(params[:url]), :title => CGI.unescape(params[:title]), :description => CGI.unescape(params[:description]), :thumbnail_url => CGI.unescape(params[:thumbnail_url]))
redirect_to links_path
end
end
app/models/link.rb
@@ -1,5 +1,5 @@
class Link < ActiveRecord::Base
- attr_accessible :description, :heading, :url, :image_url, :user_id, :author, :author_url
+ attr_accessible :url, :description, :title, :thumbnail_url
validates :url, :presence => true
belongs_to :user
acts_as_taggable
app/models/user.rb
@@ -3,5 +3,6 @@ class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
has_many :needs
+ has_many :links
acts_as_tagger
end
app/views/links/index.html.erb
@@ -28,13 +28,15 @@ $('form').on('submit', function(){
<tr>
<th></th>
<th></th>
- <th>Need</th>
- <th>Tags</th>
+ <th></th>
<th></th>
</tr>
<% @links.each do |link| %>
<tr>
<td><%= link.url %></td>
+ <td><%= link.description %></td>
+ <td><%= link.title %></td>
+ <td><%= image_tag link.thumbnail_url %></td>
</tr>
<% end %>
</table>
db/migrate/20130623155032_create_links.rb
@@ -2,11 +2,9 @@ class CreateLinks < ActiveRecord::Migration
def change
create_table :links do |t|
t.string :url
- t.string :image_url
- t.string :heading
+ t.string :title
t.text :description
- t.string :author
- t.string :author_url
+ t.string :thumbnail_url
t.integer :user_id
t.timestamps
end
db/schema.rb
@@ -48,14 +48,12 @@ ActiveRecord::Schema.define(:version => 20130624022039) do
create_table "links", :force => true do |t|
t.string "url"
- t.string "image_url"
- t.string "heading"
+ t.string "title"
t.text "description"
- t.string "author"
- t.string "author_url"
+ t.string "thumbnail_url"
t.integer "user_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "needs", :force => true do |t|