Это странная ошибка, которая действительно заставила меня прослушиваться. Во-первых, некоторый фон.Вложенные ресурсы с form_for потери первого id
У меня есть следующие вложенные ресурсы в моей конфигурации/routes.rb:
scope :requirements => { :protocol => 'https' } do
resource :user
resources :orgs do
resources :members
resources :events
resources :levels
resources :attendances
end
resources :sessions, :only => [:new, :create, :destroy]
end
Затем в приложение/контроллеры/levels_controller.rb у меня есть:
def edit
@org = Org.find(params[:org_id])
@level = OrgLevel.find(params[:id])
end
def update
@level = OrgLevel.find(params[:id])
if @level.update_attributes(params[:level])
flash[:success] = "Level details updated"
redirect_to @level
else
render 'edit'
end
end
Наконец, в приложении/просмотров/уровни/edit.html.erb, у меня есть:
<% provide(:title, "Edit #{@level.name} for #{@org.name}") %>
<div class="hero-unit">
<h2>Edit "<%= @level.name %>" membership level for <%= @org.name %></h2>
<div class="row">
<div class="span6 offset3">
<%= form_for [@org, @level], :url => org_level_path do |f| %>
<%= render 'shared/error_messages' %>
<table class="editor">
<tr>
<td class="label_x">
<%= f.label :name %>
</td>
<td colspan="3">
<%= f.text_field :name %>
</td>
</tr>
</table>
<% end %>
</div>
</div>
</div>
результат вызова https://spot-macbook.local/orgs/55/levels/162/edit нормально, но при нажатии " Сохранить изменения»приводит к перенаправлению к https://spot-macbook.local/orgs/162/levels/162 и следующее сообщение об ошибке:
ActiveRecord::RecordNotFound in LevelsController#show
Couldn't find Org with id=162
Rails.root: /Users/ogod/Projects/rails_projects/nom_de_joye_app
Application Trace | Framework Trace | Full Trace
app/controllers/levels_controller.rb:71:in `correct_user'
Request
Parameters:
{"requirements"=>{"protocol"=>"https"},
"org_id"=>"162",
"id"=>"162"}
Обратите внимание, что org_ID изменен на„162“вместо„55“. Что я делаю не так?
Спасибо! Синтаксис пути вложенных ресурсов с (parent, child) получает меня каждый раз ... –