Commit 7d0915d7 authored by 神楽坂玲奈's avatar 神楽坂玲奈

Setting Scoffled 下一版删除

git-svn-id: http://glupx.googlecode.com/svn/trunk/Reliz@51 189f022a-1064-8ae2-3e6f-c4a67275c50b
parent 57d45e87
class SettingsController < ApplicationController
# GET /settings
# GET /settings.xml
def index
@settings = Setting.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @settings }
end
end
# GET /settings/1
# GET /settings/1.xml
def show
@setting = Setting.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @setting }
end
end
# GET /settings/new
# GET /settings/new.xml
def new
@setting = Setting.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @setting }
end
end
# GET /settings/1/edit
def edit
@setting = Setting.find(params[:id])
end
# POST /settings
# POST /settings.xml
def create
@setting = Setting.new(params[:setting])
respond_to do |format|
if @setting.save
format.html { redirect_to(@setting, :notice => 'Setting was successfully created.') }
format.xml { render :xml => @setting, :status => :created, :location => @setting }
else
format.html { render :action => "new" }
format.xml { render :xml => @setting.errors, :status => :unprocessable_entity }
end
end
end
# PUT /settings/1
# PUT /settings/1.xml
def update
@setting = Setting.find(params[:id])
respond_to do |format|
if @setting.update_attributes(params[:setting])
format.html { redirect_to(@setting, :notice => 'Setting was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @setting.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /settings/1
# DELETE /settings/1.xml
def destroy
@setting = Setting.find(params[:id])
@setting.destroy
respond_to do |format|
format.html { redirect_to(settings_url) }
format.xml { head :ok }
end
end
end
module SettingsHelper
end
<%= form_for(@setting) do |f| %>
<% if @setting.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@setting.errors.count, "error") %> prohibited this setting from being saved:</h2>
<ul>
<% @setting.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :value %><br />
<%= f.text_area :value %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing setting</h1>
<%= render 'form' %>
<%= link_to 'Show', @setting %> |
<%= link_to 'Back', settings_path %>
<h1>Listing settings</h1>
<table>
<tr>
<th>Value</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @settings.each do |setting| %>
<tr>
<td><%= setting.value %></td>
<td><%= link_to 'Show', setting %></td>
<td><%= link_to 'Edit', edit_setting_path(setting) %></td>
<td><%= link_to 'Destroy', setting, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Setting', new_setting_path %>
<h1>New setting</h1>
<%= render 'form' %>
<%= link_to 'Back', settings_path %>
<p id="notice"><%= notice %></p>
<p>
<b>Value:</b>
<%= @setting.value %>
</p>
<%= link_to 'Edit', edit_setting_path(@setting) %> |
<%= link_to 'Back', settings_path %>
Reliz::Application.routes.draw do
resources :settings
resources :moderations
resources :boards
......
class CreateSettings < ActiveRecord::Migration
def self.up
create_table :settings, :primary_key => :name do |t|
t.text :value
end
change_column(:settings, :name, :string)
end
def self.down
drop_table :settings
end
end
class CreateSettings < ActiveRecord::Migration
def self.up
create_table :settings, :primary_key => :name do |t|
t.text :value
end
change_column(:settings, :name, :string)
end
def self.down
drop_table :settings
end
end
......@@ -115243,3 +115243,22 @@ Migrating to CreateSettings (20111036031160)
SQL (15.6ms) SHOW KEYS FROM `topics`
SQL (15.6ms) describe `users`
SQL (15.6ms) SHOW KEYS FROM `users`
Started GET "/settings" for 127.0.0.1 at 2011-03-31 14:32:18 +0800
Processing by SettingsController#index as HTML
User Load (15.6ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 0) LIMIT 1
Setting Load (15.6ms) SELECT `settings`.* FROM `settings`
Rendered app/themes/lotus/layouts/_header.html.erb (0.0ms)
Rendered app/themes/lotus/layouts/_top.html.erb (0.0ms)
Rendered app/themes/lotus/layouts/_footer.html.erb (0.0ms)
Rendered settings/index.html.erb within layouts/application (46.9ms)
Completed 200 OK in 297ms (Views: 109.4ms | ActiveRecord: 31.2ms)
Started GET "/css/ui-lightness/jquery-ui-1.8.11.custom.css" for 127.0.0.1 at 2011-03-31 14:33:02 +0800
Processing by ApplicationController#redirect_to_thc as HTML
Parameters: {"anything"=>"css/ui-lightness/jquery-ui-1.8.11.custom.css"}
User Load (15.6ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 0) LIMIT 1
Redirected to http://www.touhou.cc/bbs/css/ui-lightness/jquery-ui-1.8.11.custom.css?
Completed 302 Found in 125ms
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;
}
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
name:
value: MyText
two:
name:
value: MyText
require 'test_helper'
class SettingsControllerTest < ActionController::TestCase
setup do
@setting = settings(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:settings)
end
test "should get new" do
get :new
assert_response :success
end
test "should create setting" do
assert_difference('Setting.count') do
post :create, :setting => @setting.attributes
end
assert_redirected_to setting_path(assigns(:setting))
end
test "should show setting" do
get :show, :id => @setting.to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => @setting.to_param
assert_response :success
end
test "should update setting" do
put :update, :id => @setting.to_param, :setting => @setting.attributes
assert_redirected_to setting_path(assigns(:setting))
end
test "should destroy setting" do
assert_difference('Setting.count', -1) do
delete :destroy, :id => @setting.to_param
end
assert_redirected_to settings_path
end
end
require 'test_helper'
class SettingsHelperTest < ActionView::TestCase
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment