我有一个控制器“Allan”和一个控制器“Marian”,它们都是平等的,在我创建“marian”之前,“allan”工作得很好。但是现在,当我尝试创建一个新的 Alla 时,我得到了这个:
没有路由匹配 {:action=>"show", :controller=>"allans"} 尝试运行 rake 路由以获取有关可用路由的更多信息。
问题是“玛丽安”完美无缺。
怎么了?
class AllansController < ApplicationController
http_basic_authenticate_with :name => "allan", :password => "allan"
# GET /allans
# GET /allans.json
def index
@date = Date.parse(params[Date::DATE_FORMATS[:default] = "%b %e"]) rescue Date.today
@allans = Allan.where(day: @date)
@total_allans = Allan.count
@current_allans = @allans.size
respond_to do |format|
format.html # index.html.erb
format.json { render json: @allans }
end
end
# GET /allans/1
# GET /allans/1.json
def show
@allan = Allan.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @allan }
end
end
# GET /allans/new
# GET /allans/new.json
def new
@allan = Allan.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @allan }
end
end
# GET /allans/1/edit
def edit
@allan = Allan.find(params[:id])
session[:return] ||= request.referer
end
# POST /allans
# POST /allans.json
def create
@allan = Allan.new(params[:allan])
respond_to do |format|
if @allan.save
format.html { redirect_to maria_path, notice: 'Maria was successfully created.' }
format.json { render json: @allan, status: :created, location: @allan }
else
format.html { render action: "new" }
format.json { render json: @allan.errors, status: :unprocessable_entity }
end
end
end
# PUT /allans/1
# PUT /allans/1.json
def update
@allan = Allan.find(params[:id])
respond_to do |format|
if @allan.update_attributes(params[:allan])
format.html { redirect_to session.delete(:return)}
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @allan.errors, status: :unprocessable_entity }
end
end
end
# DELETE /allans/1
# DELETE /allans/1.json
def destroy
@allan = Allan.find(params[:id])
@allan.destroy
respond_to do |format|
format.html { redirect_to maria_url }
format.json { head :no_content }
end
end
end
玛丽安的续
class MariansController < ApplicationController
http_basic_authenticate_with :name => "maria", :password => "maria"
# GET /marians
# GET /marians.json
def index
@date = Date.parse(params[Date::DATE_FORMATS[:default] = "%b %e"]) rescue Date.today
@marians = Marian.where(day: @date)
@total_marians = Marian.count
@current_marians = @marians.size
respond_to do |format|
format.html # index.html.erb
format.json { render json: @marians }
end
end
# GET /marians/1
# GET /marians/1.json
def show
@marian = Marian.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @marian }
end
end
# GET /marians/new
# GET /marians/new.json
def new
@marian = Marian.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @marian }
end
end
# GET /marians/1/edit
def edit
@marian = Marian.find(params[:id])
session[:return] ||= request.referer
end
# POST /marians
# POST /marians.json
def create
@marian = Marian.new(params[:marian])
respond_to do |format|
if @marian.save
format.html { redirect_to maria_path, notice: 'Maria was successfully created.' }
format.json { render json: @marian, status: :created, location: @marian }
else
format.html { render action: "new" }
format.json { render json: @marian.errors, status: :unprocessable_entity }
end
end
end
# PUT /marians/1
# PUT /marians/1.json
def update
@marian = Marian.find(params[:id])
respond_to do |format|
if @marian.update_attributes(params[:marian])
format.html { redirect_to session.delete(:return)}
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @marian.errors, status: :unprocessable_entity }
end
end
end
# DELETE /marians/1
# DELETE /marians/1.json
def destroy
@marian = Marian.find(params[:id])
@marian.destroy
respond_to do |format|
format.html { redirect_to maria_url }
format.json { head :no_content }
end
end
end
耙路线
allans GET /allans(.:format) allans#index
POST /allans(.:format) allans#create
new_allan GET /allans/new(.:format) allans#new
edit_allan GET /allans/:id/edit(.:format) allans#edit
allan GET /allans/:id(.:format) allans#show
PUT /allans/:id(.:format) allans#update
marians GET /marians(.:format) marians#index
POST /marians(.:format) marians#create
new_marian GET /marians/new(.:format) marians#new
edit_marian GET /marians/:id/edit(.:format) marians#edit
marian GET /marians/:id(.:format) marians#show
PUT /marians/:id(.:format) marians#update
DELETE /marians/:id(.:format) marians#destroy
/allan(.:format) allans#index
maria /maria(.:format) marians#index
root / intro#index
形成艾伦
<%= form_for(@allan) do |f| %>
<% if @allan.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@allan.errors.count, "error") %> prohibited this allan from being saved:</h2>
<ul>
<% @allan.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table>
<tr>
<th>Day</th>
<th>Time</th>
<th>Lesson</th>
<th>Presence</th>
</tr>
<tr>
<th><%= f.date_select :day %></th>
<th><%= f.text_field :time, "size" => 4 %></th>
<th><%= f.text_field :lesson, "size" => 4 %></th>
<th><%= f.text_field :presence, "size" => 4 %></th>
</tr>
</table>
<br />
<table>
<tr>
<th>Name</th>
<th>O</th>
<th>W</th>
<th>P</th>
<th>G</th>
</tr>
<tr>
<th><%= f.text_field :name %></th>
<th> <%= f.text_field :oral, "size" => 2 %></th>
<th> <%= f.text_field :writing, "size" => 2 %></th>
<th> <%= f.text_field :participation, "size" => 2 %></th>
<th> <%= f.text_field :grammar, "size" => 2 %></th>
</tr>
</table>
<br />
<table>
<tr>
<th>Observations</th>
</tr>
<tr>
<th><%= f.text_field :observation %></th>
</tr>
</table>
<br />
<div class="actions">
<%= f.submit "Create" %>
</div>
<% end %>
玛丽亚
<%= form_for(@marian) do |f| %>
<% if @marian.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@marian.errors.count, "error") %> prohibited this Maria from being saved:</h2>
<ul>
<% @marian.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table>
<tr>
<th>Day</th>
<th>Time</th>
<th>Lesson</th>
<th>Presence</th>
</tr>
<tr>
<th><%= f.date_select :day %></th>
<th><%= f.text_field :time, "size" => 4 %></th>
<th><%= f.text_field :lesson, "size" => 4 %></th>
<th><%= f.text_field :presence, "size" => 4 %></th>
</tr>
</table>
<br />
<table>
<tr>
<th>Name</th>
<th>O</th>
<th>W</th>
<th>P</th>
<th>G</th>
</tr>
<tr>
<th><%= f.text_field :name %></th>
<th> <%= f.text_field :oral, "size" => 2 %></th>
<th> <%= f.text_field :writing, "size" => 2 %></th>
<th> <%= f.text_field :participation, "size" => 2 %></th>
<th> <%= f.text_field :grammar, "size" => 2 %></th>
</tr>
</table>
<br />
<table>
<tr>
<th>Observations</th>
</tr>
<tr>
<th><%= f.text_field :observation %></th>
</tr>
</table>
<br />
<div class="actions">
<%= f.submit "Create" %>
</div>
<% end %>