ben Hedef için /config/routes.rb içindeRuby on Rails Yuvalanmış kaynaklar tanımsız yöntem yolu
resources :goals do
resources :goal_entries
end
Modeller iç içe kaynakları tanımladığınız
class GoalEntry < ActiveRecord::Base
attr_accessible :code, :goal_code,
:general_increase_percentage, :general_net_sales,
belongs_to :goal, :primary_key => "code", :foreign_key => "goal_code"
validates_presence_of :code
validates_presence_of :goal_code
validates_uniqueness_of :code , :scope => :goal_code
#validates_numericality_of :general_net_sales
Hedef ebeveyn için bir GoalEntry oluşturma/düzenleme görünüm şu şekilde başlar:
<%= form_for([@goal, @goal_entry]) do |f| %>
<% if @goal_entry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@goal_entry.errors.count, "error") %>
prohibited this goal_entry from being saved:
</h2>
<ul>
<% @goal_entry.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.hidden_field :goal_code, :required => true%>
</div>
<div class="field">
<%= f.label :code %>
<%= f.number_field :code, :required => true %>
</div>
...
gol girişleri denetleyicisi güncelleme yöntemi:
def update
@goal_entry = GoalEntry.find(params[:id])
respond_to do |format|
if @goal_entry.update_attributes(params[:goal_entry])
format.html { redirect_to edit_goal_path(@goal_entry.goal), notice: 'Goal entry was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @goal_entry.errors, status: :unprocessable_entity }
end
end
end
geçerli hedef girişleri girme çalışıyor. Aşağıdaki mesajı almak bir doğrulama hata mesajı varsa Ama:
**NoMethodError in Goal_entries#update**
ActionView::Template::Error (undefined method `goal_entry_path' for #<#<Class:0x007fce30a0c160>:0x00000004199570>):
1: <%= form_for([@goal, @goal_entry]) do |f| %>
2: <% if @goal_entry.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@goal_entry.errors.count, "error") %>
app/views/goal_entries/_form.html.erb:1:in `_app_views_goal_entries__form_html_erb__827873423371803667_70261777948540'
app/views/goal_entries/edit.html.erb:3:in `_app_views_goal_entries_edit_html_erb__779650500016633360_70261777920720'
app/controllers/goal_entries_controller.rb:77:in `block (2 levels) in update'
app/controllers/goal_entries_controller.rb:72:in `update'
etc...
Birileri bunun için bir çözüm varsa ben takdir edersiniz <% if @goal_entry.errors.any? %>
yanlış bir şey mi. Teşekkürler
'undefined method 'goal_entry_path'' rotalarınızda bir goal_entry_path olduğundan emin misiniz? Varsa, düzenleme yönteminizi gönderir misiniz? – Magicmarkker
"Düzenleme" eyleminiz aşağıdakileri içeriyor mu? @goal_entry = GoalEntry.find (params [: id]) '? – MrYoshiji
"Rota yolları" yazdırılan çıktıları yayınlayabilir misiniz? – Matt