thanks that i can ask questions here. I'm using rails 5.1.4 with ruby 2.5.0. I have two models the model A and Model B.
Model A has_many bs
Model B belongs_to a
The admin-user can generate new a-entries and he can generate new b-entries. The no-admin-user can show, index or reserve.
routes.rb
resources :as, only: [:index, :show] do
resources :bs, only: [:index, :show, :reserve]
end
namespace :admin do
resources :as, only: [:create, :edit, :update, :destroy,
:show] do
member do
post :activate
get :activate
post :deactivate
get :deactivate
end
resources :bs, only: [:create, :edit, :update, :destroy, :show]
end
end
In the app/views/admin/as/show.html.erb
you can see the values of the DB Entry of an a. So now my idea is to realise that you can add new B Entries of b with a form. I tried this show.html.erb
show.html.erb
<h2><%=t("show")%></h2>
<p>
<strong><%=t("title")%></strong>
<%= @a.title %>
</p>
<p>
<strong><%=t("description")%></strong>
<%= @a.description %>
</p>
<p>
<strong><%=t("email")%>:</strong>
<%= @a.email %>
</p>
<h2><%=t("entries")%></h2>
<%= render @a.bs %>
<h2><%=t("addentry")%></h2>
<%= form_with(model: [ @a, @admin.bs.build ], local: true) do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :description %><br>
<%= f.text_area :description %>
</p>
<p>
<%= f.submit %>
</p>
The form will be generated, but the html-sourcecode don't show the "admin-route-path". But how do i this?
<form action="/as/1/bs" accept-charset="UTF-8" method="post"
How have i to change the form_with part, that i can add entries into the associated model from b?