ajout fonction tiny url
This commit is contained in:
parent
c583d7142b
commit
22e8183508
3
app/assets/javascripts/tiny_urls.js.coffee
Normal file
3
app/assets/javascripts/tiny_urls.js.coffee
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
69
app/assets/stylesheets/scaffolds.css.scss
Normal file
69
app/assets/stylesheets/scaffolds.css.scss
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
body {
|
||||||
|
background-color: #fff;
|
||||||
|
color: #333;
|
||||||
|
font-family: verdana, arial, helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p, ol, ul, td {
|
||||||
|
font-family: verdana, arial, helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #eee;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #000;
|
||||||
|
&:visited {
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
&.field, &.actions {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#notice {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field_with_errors {
|
||||||
|
padding: 2px;
|
||||||
|
background-color: red;
|
||||||
|
display: table;
|
||||||
|
}
|
||||||
|
|
||||||
|
#error_explanation {
|
||||||
|
width: 450px;
|
||||||
|
border: 2px solid red;
|
||||||
|
padding: 7px;
|
||||||
|
padding-bottom: 0;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
h2 {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 5px 5px 5px 15px;
|
||||||
|
font-size: 12px;
|
||||||
|
margin: -7px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
background-color: #c00;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
ul li {
|
||||||
|
font-size: 12px;
|
||||||
|
list-style: square;
|
||||||
|
}
|
||||||
|
}
|
3
app/assets/stylesheets/tiny_urls.css.scss
Normal file
3
app/assets/stylesheets/tiny_urls.css.scss
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the TinyUrls controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
84
app/controllers/tiny_urls_controller.rb
Normal file
84
app/controllers/tiny_urls_controller.rb
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
class TinyUrlsController < ApplicationController
|
||||||
|
|
||||||
|
http_basic_authenticate_with :name => "stats", :password => "stats", :except => [:show]
|
||||||
|
|
||||||
|
# GET /tiny_urls
|
||||||
|
# GET /tiny_urls.json
|
||||||
|
def index
|
||||||
|
@tiny_urls = TinyUrl.all
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # index.html.erb
|
||||||
|
format.json { render json: @tiny_urls }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /tiny_urls/1
|
||||||
|
# GET /tiny_urls/1.json
|
||||||
|
def show
|
||||||
|
@tiny_url = TinyUrl.find(params[:id])
|
||||||
|
@tiny_url.nbr_views = @tiny_url.nbr_views.to_i + 1
|
||||||
|
@tiny_url.save
|
||||||
|
redirect_to @tiny_url.url, :status => 301
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /tiny_urls/new
|
||||||
|
# GET /tiny_urls/new.json
|
||||||
|
def new
|
||||||
|
@tiny_url = TinyUrl.new
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.json { render json: @tiny_url }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /tiny_urls/1/edit
|
||||||
|
def edit
|
||||||
|
@tiny_url = TinyUrl.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /tiny_urls
|
||||||
|
# POST /tiny_urls.json
|
||||||
|
def create
|
||||||
|
@tiny_url = TinyUrl.new(params[:tiny_url])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @tiny_url.save
|
||||||
|
format.html { redirect_to @tiny_url, notice: 'Tiny url was successfully created.' }
|
||||||
|
format.json { render json: @tiny_url, status: :created, location: @tiny_url }
|
||||||
|
else
|
||||||
|
format.html { render action: "new" }
|
||||||
|
format.json { render json: @tiny_url.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /tiny_urls/1
|
||||||
|
# PUT /tiny_urls/1.json
|
||||||
|
def update
|
||||||
|
@tiny_url = TinyUrl.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @tiny_url.update_attributes(params[:tiny_url])
|
||||||
|
format.html { redirect_to @tiny_url, notice: 'Tiny url was successfully updated.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { render action: "edit" }
|
||||||
|
format.json { render json: @tiny_url.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /tiny_urls/1
|
||||||
|
# DELETE /tiny_urls/1.json
|
||||||
|
def destroy
|
||||||
|
@tiny_url = TinyUrl.find(params[:id])
|
||||||
|
@tiny_url.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to tiny_urls_url }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
2
app/helpers/tiny_urls_helper.rb
Normal file
2
app/helpers/tiny_urls_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module TinyUrlsHelper
|
||||||
|
end
|
3
app/models/tiny_url.rb
Normal file
3
app/models/tiny_url.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class TinyUrl < ActiveRecord::Base
|
||||||
|
attr_accessible :nbr_views, :slug, :start_at, :stop_at, :url
|
||||||
|
end
|
22
app/views/tiny_urls/_form.html.erb
Normal file
22
app/views/tiny_urls/_form.html.erb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<%= form_for(@tiny_url) do |f| %>
|
||||||
|
<% if @tiny_url.errors.any? %>
|
||||||
|
<div id="error_explanation">
|
||||||
|
<h2><%= pluralize(@tiny_url.errors.count, "error") %> prohibited this tiny_url from being saved:</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @tiny_url.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :url %><br />
|
||||||
|
<%= f.text_field :url %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
|
<%= f.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
6
app/views/tiny_urls/edit.html.erb
Normal file
6
app/views/tiny_urls/edit.html.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<h1>Editing tiny_url</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Show', @tiny_url %> |
|
||||||
|
<%= link_to 'Back', tiny_urls_path %>
|
30
app/views/tiny_urls/index.html.erb
Normal file
30
app/views/tiny_urls/index.html.erb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<h1>Listing tiny_urls</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Url courte</th>
|
||||||
|
<th>Url</th>
|
||||||
|
|
||||||
|
<th>Nbr vues</th>
|
||||||
|
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% @tiny_urls.each do |tiny_url| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= link_to "http://lepicvert.org"+tiny_url_path(tiny_url),"http://lepicvert.org"+tiny_url_path(tiny_url) %></td>
|
||||||
|
<td><%= tiny_url.url %></td>
|
||||||
|
|
||||||
|
|
||||||
|
<td><%= tiny_url.nbr_views %></td>
|
||||||
|
|
||||||
|
<td><%= link_to 'Edit', edit_tiny_url_path(tiny_url) %></td>
|
||||||
|
<td><%= link_to 'Destroy', tiny_url, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<%= link_to 'New Tiny url', new_tiny_url_path %>
|
5
app/views/tiny_urls/new.html.erb
Normal file
5
app/views/tiny_urls/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<h1>New tiny_url</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', tiny_urls_path %>
|
30
app/views/tiny_urls/show.html.erb
Normal file
30
app/views/tiny_urls/show.html.erb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Url:</b>
|
||||||
|
<%= @tiny_url.url %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Slug:</b>
|
||||||
|
<%= @tiny_url.slug %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Start at:</b>
|
||||||
|
<%= @tiny_url.start_at %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Stop at:</b>
|
||||||
|
<%= @tiny_url.stop_at %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Nbr views:</b>
|
||||||
|
<%= @tiny_url.nbr_views %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_tiny_url_path(@tiny_url) %> |
|
||||||
|
<%= link_to 'Back', tiny_urls_path %>
|
@ -1,4 +1,9 @@
|
|||||||
Survey::Application.routes.draw do
|
Survey::Application.routes.draw do
|
||||||
|
|
||||||
|
match 'u/:id' => 'tiny_urls#show', :as => :tiny_url
|
||||||
|
|
||||||
|
resources :tiny_urls
|
||||||
|
|
||||||
get "surveys/index"
|
get "surveys/index"
|
||||||
|
|
||||||
match 'sondages/merci-de-votre-participation.:f' => 'survey_sets#thanks', :as => :thanks_survey_sets, :f => "html"
|
match 'sondages/merci-de-votre-participation.:f' => 'survey_sets#thanks', :as => :thanks_survey_sets, :f => "html"
|
||||||
|
14
db/migrate/20120820162850_create_tiny_urls.rb
Normal file
14
db/migrate/20120820162850_create_tiny_urls.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class CreateTinyUrls < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :tiny_urls do |t|
|
||||||
|
t.string :url
|
||||||
|
t.string :slug
|
||||||
|
t.text :description
|
||||||
|
t.datetime :start_at
|
||||||
|
t.datetime :stop_at
|
||||||
|
t.integer :nbr_views
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
15
db/schema.rb
15
db/schema.rb
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20120816091837) do
|
ActiveRecord::Schema.define(:version => 20120820162850) do
|
||||||
|
|
||||||
create_table "answer_sets", :force => true do |t|
|
create_table "answer_sets", :force => true do |t|
|
||||||
t.integer "question_set_id"
|
t.integer "question_set_id"
|
||||||
@ -28,7 +28,7 @@ ActiveRecord::Schema.define(:version => 20120816091837) do
|
|||||||
create_table "question_sets", :force => true do |t|
|
create_table "question_sets", :force => true do |t|
|
||||||
t.integer "survey_item_id"
|
t.integer "survey_item_id"
|
||||||
t.integer "survey_set_id"
|
t.integer "survey_set_id"
|
||||||
t.string "content"
|
t.text "content", :limit => 255
|
||||||
t.boolean "boolean_content"
|
t.boolean "boolean_content"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
@ -91,4 +91,15 @@ ActiveRecord::Schema.define(:version => 20120816091837) do
|
|||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "tiny_urls", :force => true do |t|
|
||||||
|
t.string "url"
|
||||||
|
t.string "slug"
|
||||||
|
t.text "description"
|
||||||
|
t.datetime "start_at"
|
||||||
|
t.datetime "stop_at"
|
||||||
|
t.integer "nbr_views"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
15
test/fixtures/tiny_urls.yml
vendored
Normal file
15
test/fixtures/tiny_urls.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
url: MyString
|
||||||
|
slug: MyString
|
||||||
|
start_at: 2012-08-20 18:28:50
|
||||||
|
stop_at: 2012-08-20 18:28:50
|
||||||
|
nbr_views: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
url: MyString
|
||||||
|
slug: MyString
|
||||||
|
start_at: 2012-08-20 18:28:50
|
||||||
|
stop_at: 2012-08-20 18:28:50
|
||||||
|
nbr_views: 1
|
49
test/functional/tiny_urls_controller_test.rb
Normal file
49
test/functional/tiny_urls_controller_test.rb
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TinyUrlsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@tiny_url = tiny_urls(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:tiny_urls)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create tiny_url" do
|
||||||
|
assert_difference('TinyUrl.count') do
|
||||||
|
post :create, tiny_url: { nbr_views: @tiny_url.nbr_views, slug: @tiny_url.slug, start_at: @tiny_url.start_at, stop_at: @tiny_url.stop_at, url: @tiny_url.url }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to tiny_url_path(assigns(:tiny_url))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show tiny_url" do
|
||||||
|
get :show, id: @tiny_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @tiny_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update tiny_url" do
|
||||||
|
put :update, id: @tiny_url, tiny_url: { nbr_views: @tiny_url.nbr_views, slug: @tiny_url.slug, start_at: @tiny_url.start_at, stop_at: @tiny_url.stop_at, url: @tiny_url.url }
|
||||||
|
assert_redirected_to tiny_url_path(assigns(:tiny_url))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy tiny_url" do
|
||||||
|
assert_difference('TinyUrl.count', -1) do
|
||||||
|
delete :destroy, id: @tiny_url
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to tiny_urls_path
|
||||||
|
end
|
||||||
|
end
|
4
test/unit/helpers/tiny_urls_helper_test.rb
Normal file
4
test/unit/helpers/tiny_urls_helper_test.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TinyUrlsHelperTest < ActionView::TestCase
|
||||||
|
end
|
7
test/unit/tiny_url_test.rb
Normal file
7
test/unit/tiny_url_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TinyUrlTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user