0
我正在綁定對我的嵌套模型之一執行編輯操作。我不斷收到以下錯誤「未定義的方法`model_name'爲NilClass:類」Rails中嵌套模型編輯頁面的錯誤
我不知道發生了什麼事。任何幫助?
路線
resources :users, :except => [ :create, :new ] do
resources :store do
get "inbox", :on => :collection
get "openedmessages", :on => :collection
end
end
存儲操作
def edit
@store = current_user.store.id
end
def create
@store = current_user.store.new(params[:store])
end
def update
@stores = current_user.store.id
if @stores.update_attributes
flash[:success] = "Store has been updated"
render 'edit'
else
render 'edit'
end
end
信息查看編輯操作在商店
<ul class="storedashboard_header">
<li><%= link_to "Manage Gear", user_store_index_path(current_user) %></li>
<li><%= link_to "Store Appearance", edit_user_store_path(current_user, @store) %></li>
<li><%= link_to "Announcements", '#' %></li>
</ul>
<%= render "users/userdashboard_header" %>
<%= render "store/storemenu" %>
<div style="clear:both"></div>
<% flash.each do |name, msg| %>
<div class="alert alert-success">
<a class="close" data-dismiss="alert">×</a>
<%= msg %>
</div>
<% end %>
<div>
<%= simple_form_for @stores, :html => {:multipart => true, :class => 'form-horizontal'} do |f| %>
</br>
<div style="float: left;">
<%= f.input :storename %>
<%= f.input :storeimage %>
<%= f.input :storelogo %>
<%= f.button :submit, class: 'btn btn-large', style: 'margin-left: 40px;' %>
</div>
<% end %>
</div>
修訂
改變了我的控制器以下幾點:0x007fec93b97238>
決賽:
def edit
@store = Store.find(current_user.store.id)
end
def create
@store = current_user.store.new(params[:store])
end
def update
@store = Store.find(current_user.store.id)
if @store.update_attributes(params[:store])
flash[:success] = "Store has been updated"
render 'edit'
else
render 'edit'
end
end
新的錯誤更新
未定義的方法`的#<#store_path」後FIX
所需解決的觀點...
<%= simple_form_for [current_user, @store], :html => {:multipart => true, :class => 'form-horizontal'} do |f| %>
我做你的建議的修改,現在我得到一個新的錯誤,我更新我的上述問題的對象。未定義的方法'store_path'爲#<#:0x007fec93b97238> –
DaveG
更改視圖,它工作...謝謝! – DaveG