Permalink
Browse files

Adding unobtrusive js. Fix short_url usage

  • Loading branch information...
1 parent d84cd25 commit cecb02f315145c74c252a4a9900fde498774525e @davidjrice davidjrice committed Sep 15, 2011
@@ -7,3 +7,19 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+
+//$('#link_url').
+
+
+$(function (){
+ $('#new_link')
+ .bind("ajax:beforeSend", function(e) {
+ alert("PROGRESS");
+ })
+ .bind("ajax:success", function(e){
+ alert("SUCCESS");
+ })
+ .bind("ajax:error", function(e){
+ alert("FAIL");
+ })
+})
@@ -11,13 +11,19 @@ def create
@link = Link.new(params[:link])
@link.session_id = session[:session_id]
if @link.save
- redirect_to @link
+ respond_to do |format|
+ format.html { redirect_to @link }
+ format.js { head :status => :success }
+ end
else
- render :new
+ respond_to do |format|
+ format.html { render :new }
+ format.js { head :status => 500 }
+ end
end
end
- def view
+ def short
@link = Link.find(params[:id])
redirect_to root_path unless @link
@link.views += 1
@@ -3,7 +3,7 @@
<strong><%= field.to_s.upcase %></strong> <%= message %>.
<%- end -%>
<%- end -%>
-<%= form_for @link do |f| %>
+<%= form_for @link, :remote => true do |f| %>
<%= f.text_field :url, :placeholder => "Enter your URL…" %>
<%= f.submit "Squish It" %>
<%- end -%>
@@ -1,5 +1,5 @@
<h3>Short Link</h3>
-<%= link_to link_url(@link), link_url(@link) %>
+<%= link_to short_url(@link), short_url(@link) %>
<h3>Long Link</h3>
<%= link_to @link.url, @link.url %>
View
@@ -1,7 +1,7 @@
CouchbaseTinyurl::Application.routes.draw do
resources :links do
- get :view, :on => :member
+ get :short, :on => :member
end
root :to => 'links#index'
- match "/:id", :to => 'links#view', :as => :short
+ match "/:id", :to => 'links#short', :as => :short
end

0 comments on commit cecb02f

Please sign in to comment.