Permalink
Browse files

Working first version, stores url in couch and retrieves it, nice Cla…

…ss based wrapper for accessing objects in couchbase
  • Loading branch information...
1 parent e4582a9 commit 52a6252379ac355df568b5bd091e51d4d860398a @davidjrice davidjrice committed Sep 9, 2011
View
2 .rvmrc
@@ -1 +1 @@
-rvm 1.9.2@rails_3_1
+rvm 1.8.7
View
@@ -5,7 +5,10 @@ gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem "couchbase-ruby-client", :git => "git://github.com/couchbase/couchbase-ruby-client.git", :require => "couchbase"
+#gem "couchbase-ruby-client", :git => "git://github.com/couchbase/couchbase-ruby-client.git", :require => "couchbase"
+gem "validate_url"
+gem "couchbase-ruby-client", :require => "couchbase"
+# gem "couchbase-ruby-client", :path => "~/active/couchbase-ruby-client", :require => "couchbase"
# Gems used only for assets and not required
# in production environments by default.
@@ -25,6 +28,7 @@ gem 'jquery-rails'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
+# gem 'ruby-debug'
group :test do
# Pretty printed test output
View
@@ -1,13 +1,3 @@
-GIT
- remote: git://github.com/couchbase/couchbase-ruby-client.git
- revision: 16f6a9f8986abc0682e99631500fd45e231aac9f
- specs:
- couchbase-ruby-client (0.9.5)
- curb (~> 0.7.15)
- memcached (~> 1.3)
- yaji (~> 0.0.9)
- yajl-ruby (~> 0.8.2)
-
GEM
remote: http://rubygems.org/
specs:
@@ -51,6 +41,11 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.1.2)
+ couchbase-ruby-client (0.9.5)
+ curb (~> 0.7.15)
+ memcached (~> 1.3)
+ yaji (~> 0.0.5)
+ yajl-ruby (~> 0.8.2)
curb (0.7.15)
erubis (2.7.0)
execjs (1.2.4)
@@ -114,6 +109,8 @@ GEM
uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ validate_url (0.2.0)
+ activemodel (>= 3.0.0)
yaji (0.0.9)
yajl-ruby (0.8.3)
@@ -122,9 +119,10 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.1.0)
- couchbase-ruby-client!
+ couchbase-ruby-client
jquery-rails
rails (= 3.1.0)
sass-rails (~> 3.1.0)
turn
uglifier
+ validate_url
@@ -14,4 +14,8 @@ def create
end
end
+ def show
+ @link = Link.find(params[:id])
+ end
+
end
View
@@ -9,16 +9,22 @@ class Link
attr_accessor :url, :key
- validates :url, :presence => true
+ validates :url, :presence => true, :url => true
before_save :generate_key
+ def to_param
+ self.key
+ end
+
def self.popular
[]
end
def self.find(key)
+ return nil unless key
begin
- Couch.client.get(self.key)
+ url = Couch.client.get(key)
+ self.new(:key => key, :url => url)
rescue Memcached::NotFound => e
nil
end
@@ -32,14 +38,18 @@ def initialize(attributes = {})
end
def persisted?
- false
+ return false unless key
+ return false unless valid?
+ self.class.find(key).url == self.url
end
def save
- Couch.client.set(self.key, {
- :url => self.url,
- :key => self.key
- })
+ return false unless valid?
+ run_callbacks :save do
+ Couch.client.set(self.key, self.url)
+ # TODO should set return nil if sucessful? don't think so
+ end
+ true
end
def generate_key
@@ -0,0 +1,7 @@
+<%- @link.errors.each do |field, message| -%>
+ <strong><%= field %></strong> <%= message %>
+<%- end -%>
+<%= form_for @link do |f| %>
+ <%= f.text_field :url %>
+ <%= f.submit "Create" %>
+<%- end -%>
@@ -0,0 +1,5 @@
+<h3>Short Link</h3>
+<%= link_to link_url(@link), link_url(@link) %>
+<h3>Long Link</h3>
+<%= link_to @link.url, @link.url %>
+
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
-CouchbaseTinyurl::Application.config.session_store :cookie_store, key: '_couchbase-tinyurl_session'
+CouchbaseTinyurl::Application.config.session_store(:cookie_store, :key => '_couchbase-tinyurl_session')
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json]
+ wrap_parameters :format => [:json]
end
# Disable root element in JSON by default.

0 comments on commit 52a6252

Please sign in to comment.