I’m having a bit of a trouble on my edit form. For some reason my select helper is not working properly on the edit action. It seems to ignore for some reason the option :prompt=>true and does not show the “Please select” message. But only on the edit action, the new action is working just fine.
the snippet from the form partial:
f.select :category_id, @categories, {:prompt => true}
the 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
the 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?
This work for me.
However, I usually try to avoid doing prompts with the rails form helpers because they never seem to behave right.
Alternatively, I’ve done it this way:
which pushs the array to the front of your @categories array