Option: prompt => true from f.select does not work on the editing action

I am having problems with my edit form. For some reason, my selection assistant is not working properly in the editing action. For some reason, it seems that the option: prompt => true is being ignored and the message "Please select" is not displayed. But only in the edit action does the new action work fine.

fragment from the form:

f.select :category_id, @categories, {:prompt => true}

edit action

  def edit
    @page = Page.find(params[:id])
    @categories = Category.where(:cat_type=>"page").map { |c| [t("category.#{c.slug}",:default=>"#{c.name}"), c.id] }
  end

new action

  def new
    @page = Page.new
    @categories = Category.where(:cat_type=>"page").map { |c| [t("category.#{c.slug}",:default=>"#{c.name}"), c.id] }

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @page }
    end
  end

Any idea?

+5
source share
4 answers
f.select :category_id, @categories, :include_blank => "whatever your prompt says"

This work is for me.

However, I usually try to avoid making tips with the help of rails because they never behave correctly.

:

f.select :category_id, @categories.unshift(["whatever your prompt says", value])

@categories

+12

Apidock:

select(object, method, choices, options = {}, html_options = {})

, :

f.select :category_id, options_from_collection_for_select(@categories, :id, :name), {prompt: 'Please select ...' }, { class: 'form-control' }
+2

It works as expected. It does not display a prompt if a value has been selected and saved previously.

Hint against the choice - "The main difference is that if the choice already matters, then: the invitation will not be displayed, whereas: include_blank will always be."

Refer to this API note .

+1
source

select the option for the form for the method with the hint value and html classes:

f.select(:subcription_with, options_for_select(['paypal', 'stripe']), {:prompt => 'Select Payment Method'}, {:class => "form-control slct-box"})

enter image description here

0
source

All Articles