2012-03-24 11 views
0

私はスカベンジャーの狩猟を作成するためのWebアプリケーションを開発中です。問題は、私は新しい狩猟を保存するためにRailsを納得させるように見えるとは思わない。ここに私のセットアップです。私が間違っていることは何か考えていますか?新しいRails 3 ActiveRecordモデルを保存できません

モデル:

class Hunt < ActiveRecord::Base 
    attr_accessible :name 

    validates :name, :presence => true, 
        :length => { :maximum => 50 } , 
        :uniqueness => { :case_sensitive => false } 
end 

コントローラー:

class HuntController < ApplicationController 

    def index 
    @title = "All Hunts" 
    @hunts = Hunt.order("name ASC")  
    end 

    def show 
    @hunt = Hunt.find(params[:id]) 
    @title = @hunt.name  
    end 

    def new 
    @hunt = Hunt.new 
    @title = "New Hunt" 
    end 

    def create 
    @hunt = Hunt.new(params[:hunt]) #fixed type (used to be this: Hunt.new(params[:id])) 
    if @hunt.save 
     flash[:success] = "Hunt created!" 
     redirect_to index 
    else 
     @title = "New Hunt" 
     render 'new' 

    end 

    ... 

end 

ビュー

<h1>Sign up</h1> 

    <%= form_for(@hunt) do |f| %> 

     <div class="field"> 
     <%= f.label :name %><br /> 
     <%= f.text_field :name %> 
     </div> 

     <div class="actions"> 
     <%= f.submit "Sign up" %> 
     </div> 
    <% end %> 

ルート

MyChi::Application.routes.draw do 


    get "hunts/index" 
    get "hunts/new" 
    get "hunts/create" 
    get "hunts/show" 
    get "hunts/list" 
    get "hunts/edit" 
    get "hunts/delete" 

    match '/hunts', :to => 'hunts#index' 

    resource :hunts 

    ..... 

    root :to => "pages#home" 

    match ':controller(/:action(/:id(.:format)))' 

EDIT:新しい狩りが追加されると、ユーザーはインデックスにリダイレクトされますが、成功のフラッシュ通知はありません。あなたのアクションを作成するには

答えて

2

、Hunt.new(のparams [:IDを])に変更します。

+0

その種類を見ていない([狩り]のparams)がHunt.newに。ありがとう。残念ながら、それはトラブルメーカーではありません。私はタイプミスを修正しましたが、まだ問題があります。 –

+0

コントローラクラスが複数の "HuntsController"になっている必要があります。ログをチェックしてエラーが発生していないかどうか確認できますか? –

+0

"HuntController"を "HuntsController"に変更し、ルートファイルを更新してサーバーを再起動しました。残念ながら、それは私のアプリの動作を変更していません。これを引き起こしている可能性のある他のアイデアは? –

関連する問題