1

I'm using shallow nesting in Rails, similar to the example here

My routes.rb is configured with:

  resources :applications do
    resources :domains, shallow: true
  end

I have used rails scaffold to generate both models and associations, in order to add new domain to application, I can get there via

option #1

   /domains/new

option #2 via its parent resource

   /applications/:application_id/domains/new

Currently the form displays drop down to associate domain with its parent upon creation.

enter image description here

How can I hide this dropdown menu option if user get to the form via option 2 and display if if user get to the form via option 1?

Your thoughts is highly appreciated.

Thanks

2 Answers 2

2

Just check params[:application_id]:

<%= render 'menu' if params[:application_id].blank? %>
Sign up to request clarification or add additional context in comments.

Comments

2

I think you can check if the parameter application_id is nil and set it in a hidden field if it is not nil coming from option #1.

Code example:

<%if params[:application_id].nil? %>
  display your dropdown here
<%else%>
  <%= f.hidden_field :application_id, :value => params[:application_id] %>
<%end%>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.