Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new resource with params #2723

Open
y0608 opened this issue Dec 11, 2024 · 0 comments
Open

Creating a new resource with params #2723

y0608 opened this issue Dec 11, 2024 · 0 comments

Comments

@y0608
Copy link

y0608 commented Dec 11, 2024

  • What would you like to be able to do? Can you provide some examples?
    Create a new resource using params.
    The new method doesn't support params. I want to be able to do: Model.new params. This is because I am trying to make dynamic select fields - like so: https://youtu.be/vKjWXMHzOoA?list=LL&t=884

  • How could we go about implementing that?
    This can be easily achieved by using new_resource(resource_params) and adding a simple check if there are any parameters specified. If not - proceed with default behaviour.

# application_controller.rb

    def new
      if params[resource_class.model_name.element].present?
        resource = new_resource(resource_params)
      else
        resource = new_resource
      end
      authorize_resource(resource)
      render locals: {
        page: Administrate::Page::Form.new(dashboard, resource)
      }
    end
y0608 added a commit to y0608/administrate that referenced this issue Dec 11, 2024
…pdown.

Issue [2723](thoughtbot#2723)

I want to create dynamic dropdowns in a form.
Update a field based on the selected value of another dropdown.
I achieve this by calling Model.new model_params in the controller, which is currently not supported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant