2

For training, I create a simple rails app. Then

rails g scaffold Tache titre:string desc:text --skip-stylesheets
rake db:migrate
rails g bootstrap:install static

After that, I start the server, and I click on "Add Tache", I fill the 2 fields, and then I got this error:

param is missing or the value is empty: tach

   # Never trust parameters from the scary internet, only allow the white list through.
    def tach_params
      params.require(:tach).permit(:titre, :desc)
    end
end

So I looked in taches_controller.rb, and I notice that tache is truncated. If I change:

      params.require(:tach).permit(:titre, :desc)

to

      params.require(:tache).permit(:titre, :desc)

It works. And this line of code is not the only one with the last character truncated.

Example:

    def update
    respond_to do |format|
      if @tach.update(tach_params)
        format.html { redirect_to @tach, notice: 'Tache was successfully updated.' }
        format.json { render :show, status: :ok, location: @tach }
      else
        format.html { render :edit }
        format.json { render json: @tach.errors, status: :unprocessable_entity }
      end
    end
  end

Can you tell me why it is truncated like this ? I must have miss something but I cannot see what.

Regards

Siguza
  • 21,155
  • 6
  • 52
  • 89
Shadow
  • 23
  • 2

1 Answers1

3

This happens where Rails tries to singularize the plural taches. You can try this out in the Rails console:

"taches".singularize
# => "tach"

You can correct this behaviour by putting this in an initializer (preferably config/initializers/inflections.rb):

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'tache', 'taches'
end

Be sure to restart your Rails console and server. Then you can try again:

"taches".singularize
# => "tache"
fivedigit
  • 18,464
  • 6
  • 54
  • 58