Prepopulate Reform with GET vars

112 views Asked by At

How can you prepopulate a Reform form object with variables from the query string?

I understand how to call prepopulate! but how do I access a variable on the URL from within the Reform contract?

For example:

/example/new?lang=en

property :language, virtual: true, prepopulator: ->(*) { ??? }
1

There are 1 answers

0
Eelco On BEST ANSWER

To follow the docs on Trailblazer GitHub:

class AlbumsController
  def new
    @form = AlbumForm.new(Album.new)
  end

should be:

class AlbumsController
  def new
    @form = AlbumForm.new(Album.new(language: params[:lang]))
  end