Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nested namespace on form_for helper method - Rails

Hello guys so i have two namespaces, one nested inside another of the form

admin (namespace) inside admin i have blog (namespace)

i know that i can put the namespace like below in the form-for helper.

<%= form_for [:blog, @post] do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="large-12 columns">
    <div class="field panel">
      <%= f.label :title %><br>
      <%= f.text_field :title %>
    </div>

    <div class="field panel">
      <%= f.label :body %><br>
      <%= f.text_field :body %>
    </div>

    <div class="actions">
      <%= f.submit %>
      <%= link_to 'Back', admin_blog_posts_path %>
    </div>
  </div>

<% end %>

but how can i also prefix :admin namespace in front of that?

like image 764
Petros Kyriakou Avatar asked Nov 24 '25 02:11

Petros Kyriakou


1 Answers

Found it.

for future reference

you just add a comma depending on the order of your namespaces

in the case above

<%= form_for [:admin,:blog, @post] do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="large-12 columns">
    <div class="field panel">
      <%= f.label :title %><br>
      <%= f.text_field :title %>
    </div>

    <div class="field panel">
      <%= f.label :body %><br>
      <%= f.text_field :body %>
    </div>

    <div class="actions">
      <%= f.submit %>
      <%= link_to 'Back', admin_blog_posts_path %>
    </div>
  </div>
like image 99
Petros Kyriakou Avatar answered Nov 26 '25 17:11

Petros Kyriakou