If your form data is sent via fields with name attributes of type user[profile_attributes][gender] (all have the user prefix), you can check if :user exists in params .
... if params.include?(:user)
If for any reason (for example, coming from the route) params[:user] will already matter even for GET requests, you can look for a specific form field that has a value. For example, you can add a hidden field
<%= f.hidden_field :some_field, :value => true %>
and check it in your condition
... if params[:user].include?(:some_field)
You can also check if the request passed using the POST method
... if request.post?
Does this work for other methods like request.put? for the update method.
source share