添加app\controllers\shares_controller.rb及相关文件用来作为api演示的小例子,Client.html放在根目录下作为演示客户端
This commit is contained in:
parent
bf1f9b8e19
commit
e635237acd
|
@ -0,0 +1,25 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
Client
|
||||
</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<hr />
|
||||
<h2>这是一张图片</h2>
|
||||
<p>photo<a href="http://10.0.47.15:3000/shares/new?access_token='2d3dda45dsd'&comment='verygood'&title=davide&share_type=1&url=http://www.baidu.com"> Share A </a></p>
|
||||
<hr />
|
||||
|
||||
<h2>这是一段视频</h2>
|
||||
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=kaka&share_type=2&url=http://www.sina.com"> Share B </a></p>
|
||||
<hr />
|
||||
|
||||
<h2>这是一篇文章</h2>
|
||||
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=pepe&share_type=3&url=http://www.sina.com"> Share C </a></p>
|
||||
<hr />
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,56 @@
|
|||
body { background-color: #fff; color: #333; }
|
||||
|
||||
body, 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; }
|
||||
a:visited { color: #666; }
|
||||
a:hover { color: #fff; background-color:#000; }
|
||||
|
||||
div.field, div.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;
|
||||
}
|
||||
|
||||
#error_explanation 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;
|
||||
}
|
||||
|
||||
#error_explanation ul li {
|
||||
font-size: 12px;
|
||||
list-style: square;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
|
@ -0,0 +1,92 @@
|
|||
class SharesController < ApplicationController
|
||||
# GET /shares
|
||||
# GET /shares.json
|
||||
def index
|
||||
@shares = Share.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @shares }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /shares/1
|
||||
# GET /shares/1.json
|
||||
def show
|
||||
@share = Share.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @share }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /shares/new
|
||||
# GET /shares/new.json
|
||||
def new
|
||||
@share = Share.new
|
||||
|
||||
#add by mkz 抓取参数传给share
|
||||
@share[:access_token] = params[:access_token]
|
||||
@share[:comment] = params[:comment]
|
||||
@share[:title] = params[:title]
|
||||
@share[:url] = params[:url]
|
||||
@share[:share_type] = params[:share_type]
|
||||
@share.save
|
||||
#
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @share }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /shares/1/edit
|
||||
def edit
|
||||
@share = Share.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /shares
|
||||
# POST /shares.json
|
||||
def create
|
||||
@share = Share.new(params[:share])
|
||||
|
||||
respond_to do |format|
|
||||
if @share.save
|
||||
format.html { redirect_to @share, notice: 'Share was successfully created.' }
|
||||
format.json { render json: @share, status: :created, location: @share }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @share.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /shares/1
|
||||
# PUT /shares/1.json
|
||||
def update
|
||||
@share = Share.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @share.update_attributes(params[:share])
|
||||
format.html { redirect_to @share, notice: 'Share was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @share.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /shares/1
|
||||
# DELETE /shares/1.json
|
||||
def destroy
|
||||
@share = Share.find(params[:id])
|
||||
@share.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to shares_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module SharesHelper
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Share < ActiveRecord::Base
|
||||
attr_accessible :access_token, :comment, :share_type, :title, :url
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
<%= form_for(@share) do |f| %>
|
||||
<% if @share.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@share.errors.count, "error") %> prohibited this share from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @share.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :access_token %><br />
|
||||
<%= f.text_field :access_token %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :comment %><br />
|
||||
<%= f.text_field :comment %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :url %><br />
|
||||
<%= f.text_field :url %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :title %><br />
|
||||
<%= f.text_field :title %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :share_type %><br />
|
||||
<%= f.number_field :share_type %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -0,0 +1,6 @@
|
|||
<h1>Editing share</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @share %> |
|
||||
<%= link_to 'Back', shares_path %>
|
|
@ -0,0 +1,31 @@
|
|||
<h1>Listing shares</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Access token</th>
|
||||
<th>Comment</th>
|
||||
<th>Url</th>
|
||||
<th>Title</th>
|
||||
<th>Share type</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @shares.each do |share| %>
|
||||
<tr>
|
||||
<td><%= share.access_token %></td>
|
||||
<td><%= share.comment %></td>
|
||||
<td><%= share.url %></td>
|
||||
<td><%= share.title %></td>
|
||||
<td><%= share.share_type %></td>
|
||||
<td><%= link_to 'Show', share %></td>
|
||||
<td><%= link_to 'Edit', edit_share_path(share) %></td>
|
||||
<td><%= link_to 'Destroy', share, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Share', new_share_path %>
|
|
@ -0,0 +1,5 @@
|
|||
<h1>New share</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', shares_path %>
|
|
@ -0,0 +1,30 @@
|
|||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Access token:</b>
|
||||
<%= @share.access_token %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Comment:</b>
|
||||
<%= @share.comment %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Url:</b>
|
||||
<%= @share.url %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Title:</b>
|
||||
<%= @share.title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Share type:</b>
|
||||
<%= @share.share_type %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_share_path(@share) %> |
|
||||
<%= link_to 'Back', shares_path %>
|
|
@ -16,6 +16,9 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
RedmineApp::Application.routes.draw do
|
||||
resources :shares
|
||||
|
||||
|
||||
get "tags/index"
|
||||
|
||||
get "tags/show"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class CreateShares < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :shares do |t|
|
||||
t.string :access_token
|
||||
t.string :comment
|
||||
t.string :url
|
||||
t.string :title
|
||||
t.integer :share_type
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130729033444) do
|
||||
ActiveRecord::Schema.define(:version => 20130801081314) do
|
||||
|
||||
create_table "a_user_watchers", :force => true do |t|
|
||||
t.string "name"
|
||||
|
@ -516,12 +516,13 @@ ActiveRecord::Schema.define(:version => 20130729033444) do
|
|||
add_index "settings", ["name"], :name => "index_settings_on_name"
|
||||
|
||||
create_table "shares", :force => true do |t|
|
||||
t.string "title"
|
||||
t.string "type"
|
||||
t.string "access_token"
|
||||
t.string "comment"
|
||||
t.string "url"
|
||||
t.date "created_on"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "title"
|
||||
t.integer "share_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "students", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue