0

UserモデルとモデルがありStorefrontます。

何らかの理由で、/ storefronts / newに移動しようとすると、次のエラーが発生します。

ルーティングエラールートが一致しません{:action => "edit"、:controller => "storefronts"、:id =>#ストアフロントID:nil、名前:nil、user_id:4、created_at:nil、updated_at:nil、説明: nil、場所:nil>}

これを理解しようとして3時間そこにいました。昨日は機能していました。 「新しい」アクションのときに、なぜ:action => "edit"と表示されるのですか?

これが私のコードです:

class Storefront < ActiveRecord::Base
  attr_accessible :name, :location, :description
  belongs_to :user
end

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password
  has_one :storefront
end

class StorefrontsController < ApplicationController
  before_filter :check_auth, only: [:new, :edit, :update]

  def index
    @storefronts = Storefront.all
  end

  def new
    @storefront = current_user.build_storefront
  end

  def create
    @storefront = current_user.build_storefront(params[:storefront])
    if @storefront.save
      redirect_to edit_storefront_path(@storefront)
    else
      render 'new'
    end
  end

def show
    @storefront = Storefront.find(params[:id])
  end

  def edit
    @storefront = Storefront.find(params[:id])
  end

  def update
    @storefront = Storefront.find(params[:id])
    if @storefront.update_attributes(params[:storefront])
      redirect_to @storefront
    else
      render 'edit'
    end
  end
end


Pbf::Application.routes.draw do
  resources :sessions, :only => [:new, :create, :destroy]
  resources :users
  resources :storefronts

  root :to => 'storefronts#index'
  match '/signup',  to: 'users#new'
  match '/login', to: 'sessions#new'
  match '/logout', to: 'sessions#destroy'
end

私が使用しているリンク(ここに問題があります)

  <% if current_user.storefront %>
    <%= link_to "Manage Storefront", edit_storefront_path(current_user.storefront) %>
  <% else %>
    <%= link_to "Open Storefront!", openstore_path %>
  <% end %>

前もって感謝します!

編集:私のrake routes

   sessions POST   /sessions(.:format)             sessions#create
new_session GET    /sessions/new(.:format)         sessions#new
    session DELETE /sessions/:id(.:format)         sessions#destroy
      users GET    /users(.:format)                users#index
            POST   /users(.:format)                users#create
   new_user GET    /users/new(.:format)            users#new
  edit_user GET    /users/:id/edit(.:format)       users#edit
       user GET    /users/:id(.:format)            users#show
            PUT    /users/:id(.:format)            users#update
            DELETE /users/:id(.:format)            users#destroy
storefronts GET    /storefronts(.:format)          storefronts#index
            POST   /storefronts(.:format)          storefronts#create  
new_storefront GET    /storefronts/new(.:format)   storefronts#new 
edit_storefront GET    /storefronts/:id/edit(.:format) storefronts#edit
 storefront GET    /storefronts/:id(.:format)      storefronts#show
            PUT    /storefronts/:id(.:format)      storefronts#update
            DELETE /storefronts/:id(.:format)      storefronts#destroy
4

3 に答える 3

2

私には、あなたの見方に誤りがあるように見えます。パラメータとして渡さずにapp/views/storefronts/new.html.erb誤って参照しています。あなたはおそらくしたいedit_storefront_pathstorefront_idstorefronts_path

于 2013-01-18T19:55:51.973 に答える
0

それnew_storefronts_pathは収集ルートです。単数形を渡すと、名前付きルートを宣言していない場合はメンバールートと見なされます。そのため、ルートはアクションを編集するために選択し、ID 4に関しては、慣例に従ってIDを渡していないのでnil.object_id4です。 。

于 2013-01-18T19:50:43.337 に答える
0

おそらく問題は、ルーターが「:id」の種類から「new」を認識できないことです。編集ルート宣言に制約を追加してみてください

get 'storefronts/:id/edit' => 'storefronts#edit', :id => /[\d]*/

その場合、デジタルIDのみが編集アクションの呼び出しとして解釈されます。

于 2013-01-18T19:53:34.907 に答える