2

I am very new to Rails and I am facing a somehow weird problem, and my googling didn't helped me so far...

I have implemented a classical CRUD ressource following the Getting Started with Rails guide and I am blocking on the "update" part: http://guides.rubyonrails.org/getting_started.html#updating-articles

This is part of my model "Devwork":

class Devwork < ActiveRecord::Base
  validates :short_title, presence: true, uniqueness: true
  validates :title_fr, presence: true, allow_blank: false

  translates :title, :summary, :description
  globalize_accessors
end

I am using the Globalize gem to persist localized data, and Globalize-accessor for the helpers.

Here is the controller's update action:

class DevworksController < ApplicationController
  def update
    @devwork = Devwork.find(params[:id])

    if @devwork.update(devwork_params)
      redirect_to @devwork
    else
      render :edit
    end
  end

  private
  def devwork_params
    params.require(:devwork)
        .permit!
  end
end

And part of the form:

<%= form_for @devwork do |f| %>
<p>
  <%= f.label :short_title %>
  <%= f.text_field :short_title %>
</p>
<p>
  <%= f.label :title_fr %>
  <%= f.text_field :title_fr %>
  <%= f.label :title_en %>
  <%= f.text_field :title_en %>
</p>
<p>
  <%= f.submit %>
</p>
<% end %>

short_title and title_fr are mandatory, while there exist another field title_en which is not. I want the update form to be shown again if the update fails (typically because of empty title_fr).

But it doesn't work. The update never fails (never entering render :edit) even if title_fr is empty. In fact, the update does nothing if one of the field is empty, it only updates non-empty fields.

I surely missed something somewhere, but I can't figure it out... perhaps a missuses of Globalize ?

Thanks for your help !

VooDooS
  • 156
  • 6

0 Answers0