0

I've got a route that looks like this:

get ':q', to: 'foo#bar'

and I can access it inside my foo_controller through:

params[:q].

Is it somehow possible to nest the params-hash so that it can access it through:

params[:namespace][:q]

2
  • The structure of the params hash has nothing to do with the routes. Rather it just depends on what query string or request body was sent by the client (which boils down to the link/form). What get :q does is creates a route that matches the path /q. Commented Mar 3, 2018 at 16:41
  • 1
    You nest inputs by naming them [foo][bar]baz which Rack then deserializes into nested hashes. You can achieve this with fields_for but you should really get a grasp of the fundamentals first. Commented Mar 3, 2018 at 16:54

1 Answer 1

1

yes, its possible and very easy to do so. 1. Declare the routes properly for the nested resources. refer to the link1 below.

  1. allow nested attributes in the strong parameters. like this:

    params.require(:abc).permit(:name, :email, custome_attribute: { :id, :_delete, :name})

Remember :id and :_delete is neceesary if you want to delete the nested resources. Now construct your form using rails form builder. follow the 2nd link below.

Please go through the following tutorial:

http://guides.rubyonrails.org/routing.html#nested-resources

http://guides.rubyonrails.org/form_helpers.html#nested-forms

Sign up to request clarification or add additional context in comments.

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.