2013-10-31 69 views
0

我有一个控制器“艾伦”和一个控制器“玛丽安” 他们都是平等的,我之前创建的“玛丽安”“艾伦“工作得很好。 但是现在,当我尝试创建一个新的阿拉,我得到这个:没有路由匹配{:动作=>“秀”,:控制器=>“allans”}

没有路由匹配{:动作=>“秀”,:控制器=>“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 %> 
+0

基于您的代码,你应该得到一个错误说东西像allans控制器未定义的方法maria_path。但是您可能已经剪切并粘贴以节省堆栈溢出的一些时间。这不是一个很好的解决办法,但除此之外,我不知道会产生这个错误,假设你是从URL调用你的表单,你是吗?/ allans/new? – trh

+0

我没有收到有关玛丽亚的错误。是的,我从URL调用它。 – Allan

+0

这是我在控制台中看到:'入门使用“/ allans /新”为127.0.0.1,在2013年10月31日16时44分58秒-0200 处理由AllansController#新的HTML渲染 allans/_form。 html.erb(5.0ms) 在布局/应用程序中呈现allans/new.html.erb(11.0ms) 在18ms内完成500个内部服务器错误 ActionController :: RoutingError(No route matches {:action =>“show” ,:controller =>“allans”}): app/views/allans/new.html.erb:5:in _app_views_allans_new_html_erb__577930706_33554424' app/controllers/allans_controller.rb:31:in'new'' – Allan

回答

0

我真的不知道问题是什么,但我复制了玛丽亚的代码,改变了名称“玛丽亚”,以“艾伦”,和它的工作。所以也许是我没有注意到就改变了。

相关问题