lundi 13 avril 2015

ActionView::Template::Error (Undefined method new_contract_months_path for ) after remove model

I got this error when I tried to create a simple form in rails 3. My _new_contract_month.html.erb is:



<% provide(:title, 'New Contract') %>
<div class="row">
<div>
<%= form_for NewContractMonth.new, url: new_contract_month_path do |f| %>
<%= f.label :serial_number, "Serial Number", :size => 60 %>
<%= f.text_field :serial_number %>
<%= f.label :sale, "Sele", :size => 60 %>
<%= f.text_field :sale %>
<%= f.label :goal_profit, "Goal profit rate", :size => 60%>
<%= f.text_field :goal_profit %>
<%= f.label :alert_mail, "Alert Mail" %>
<%= f.check_box :alert_mail %>
<%= f.label "Date" %>
<%= f.select :date, NewContractMonth::DATE.collect {|s| [l("date_#{s}"), s]}%>
<%= f.label "Start Date"%>
<%= f.text_field :start_date, :size => 10 %><%= calendar_for('new_contract_month_start_date') %>
<%= f.label "End Date"%>
<%= f.text_field :end_date, :size => 10 %><%= calendar_for('new_contract_month_end_date') %>
<%= f.label "Description", :size => 100%>
<%= f.textfield :description%>
<%= f.label "Status"%>
<%= f.select :status, NewContractMonth::STATUS.collect {|f| [l("status_#{f}"), f]}%>
<% end %>
<%= f.summit "Save"%>
</div>
</div>


my route.rb is:



# Plugin's routes
# See: http://ift.tt/GVpneB
if Rails.version.to_f >= 3.0
match 'attendance_time_money/index/:id', :to => 'attendance_time_money#index', :via => :get
match 'analysis_time_money/index/:id', :to => 'analysis_time_money#index', :via => :get
match 'setting_time_money/index/:id', :to => 'setting_time_money#index', :via => :get
match 'setting_time_money/new/:id' , :to => 'setting_time_money#new', :via => :get
match 'setting_time_money/new_contract_month/:id' , :to => 'setting_time_money#new_contract_month', :via => :get


else # Routes for older Rails routes
ActionController::Routing::Routes.draw do |map|
map.connect '/attendance_time_money/index/:id', :controller => 'attendance_time_money', :action => 'index'
map.connect '/analysis_time_money/index/:id', :controller => 'analysis_time_money', :action => 'index'
map.connect '/setting_time_money/index/:id', :controller => 'setting_time_money', :action => 'index'
end
end


my controller:



class SettingTimeMoneyController < ApplicationController
unloadable


def index
@new_contract_month = NewContractMonth.all
@new_contract_version = NewContractMonth.all
end

def new_contract_month
@new_contract_month ||= NewContractMonth.new
@new_contract_version ||= NewContractVersion.new
end

def edit_contract
@new_contract_month = NewContractMonth.find(params[:id])
@new_contract_version = NewContractMonth.find(params[:id])
end

def update_contract
respond_to do |format|
if @new_contract.update(new_contract_params)
format.html { redirect_to @new_contract, notice: 'New contract was successfully updated'}
format.json { head :no_content }
else
format.html { render 'new_contract'}
format.json { render json: @new_contract.errors, status: :unprocessable_entity }
end
end
end


end


I searched google and find a solution to fix this problem by add :as => new_contract_month to route file. Unfortunately, after that, I delete my new_contract_month.rb model and then add it again(the same name, with more attributes). When I run my app again, the error comeback and I get stuck until now. So can someone help me?


Aucun commentaire:

Enregistrer un commentaire