我是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的所有信息,我是否必须仅限制行动? –