我是RoR的新手,我嘗試使用後&用戶構建經典的網絡應用程序。 有一個模型&控制器(在線),允許用戶把他的帖子放在公共牆上,並帶有此操作的新信息。 我目前正在嘗試通過修改模型Onlines來修改與此操作(Onlines)相關聯的嵌套窗體。 但我無法訪問我的控制器的這個動作,我不明白爲什麼?從其他控制器訪問我的動作編輯
我的代碼::
人在線控制器:
class OnlinesController < ApplicationController
before_action :set_online
def edit
end
private
def set_online
@post = Post.find(params[:post_id])
@online = Online.find_by(params[:id])
end
end
柱控制器:
class PostsController < ApplicationController
before_action :set_online
def show
@online.post_id = @post.id
end
private
def set_online
@onlines = Online.find_by(id: params[:id])
end
end
查看/職位/顯示:`
<div class="btn-group" role="group" aria-label="...">
<%= link_to '- taked - ', edit_online_path(@online), data: { confirm: 'Confirmer la mise en ligne de #{@title}?' }, class: "btn btn-primary " %>
</div>
查看/人在線/編輯:
<%= simple_form_for([@post, @onlines]) do |f| %>
<div class="row">
<div class="col-md-12">
<div id="Order">
<%= f.simple_fields_for :orders do |order| %>
<%= render 'orders_fields', f: order %>
<%end%>
<div class="Order_links">
<%= link_to_add_association 'Ajouter une part', f, :orders, class: "btn btn-default" %>
</div>
</div>
</div>
</div>
<div class="form-group text-center">
<%= f.submit "Pusher", class: 'btn btn-success' %>
</div>
<% end %>
路線:
Rails.application.routes.draw do
get 'profiles/show'
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
devise_for :users, :controllers => { registrations: 'registrations' }
resources :posts do
resources :comments
resources :onlines
end
get ':pseudo', to: 'profiles#show', as: :profile
get ':pseudo/edit', to: 'profiles#edit', as: :edit_profile
patch ':pseudo/edit', to: 'profiles#update', as: :update_profile
get ':post_id/online/new', to: 'online#new', as: :new_online
post ':post_id/online/:id/edit', to: 'onlines#edit', as: :edit_online
root 'posts#index'
所以,如果你能引導我成功的這一行動也將是美好的,謝謝!
感謝您的及時回答 我編輯我的問題,向您展示我所有的路線 我不明白你告訴我關於set_online的所有信息,我是否必須僅限制行動? –