diff options
| author | Teddy Wing | 2018-02-02 17:44:32 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-02-06 14:47:31 +0100 | 
| commit | 3a80c4217751a2f5509d0a67d531a65ff5b047df (patch) | |
| tree | 1fbcd325bdbae783d25e907f1c9cab20f8aa4f6b /app | |
| parent | 4f58c4eaca46dc975aa907840cdbe067f6225d5e (diff) | |
| download | chouette-core-3a80c4217751a2f5509d0a67d531a65ff5b047df.tar.bz2 | |
StopArea: Don't auto-initialise a value for the `kind` attribute
We were getting this error on `ReferentialVehicleJourneys#index`:
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Started GET "/referentials/9/vehicle_journeys" for 172.28.10.14 at 2018-02-01 17:48:32 +0100
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Processing by ReferentialVehicleJourneysController#index as HTML
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Parameters: {"referential_id"=>"9"}
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: locale set to :fr
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Rendered referential_vehicle_journeys/_filters.html.slim (37.0ms)
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Rendered referential_vehicle_journeys/index.html.slim within layouts/application (54.3ms)
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Completed 500 Internal Server Error in 73ms (ActiveRecord: 10.4ms)
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: ActionView::Template::Error (missing attribute: kind):#012    23:         = f.input :published_journey_name_lteq, label: false, wrapper_html: { class: 'w45'}#012    24:     .form-group.togglable#012    25:       = f.label Chouette::StopArea.model_name.human.pluralize, required: false, class: 'control-label'#012    26:       = f.input :stop_area_ids, collection: @all_stop_areas.select(:id, :name).order(name: :asc), checked: params[:q] && params[:q][:stop_area_ids], as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}, multiple: true#012    27:     .form-group.togglable#012    28:       = f.label Chouette::VehicleJourney.human_attribute_name(:purchase_window), class: 'control-label'#012    29:       .filter_menu#012  app/models/chouette/stop_area.rb:51:in `block in <class:StopArea>'#012  app/views/referential_vehicle_journeys/_filters.html.slim:26:in `block in _app_views_referential_vehicle_journeys__filters_html_slim__692539656386688985_47285414929500'#012  app/views/referential_vehicle_journeys/_filters.html.slim:1:in `_app_views_referential_vehicle_journeys__filters_html_slim__692539656386688985_47285414929500'#012  app/views/referential_vehicle_journeys/index.html.slim:9:in `_app_views_referential_vehicle_journeys_index_html_slim___336434325333090796_47285419865660'
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Processing by ErrorsController#server_error as HTML
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: Parameters: {"referential_id"=>"9"}
    Feb  1 17:48:32 chouette-dev rails/chouette[18900]: locale set to :fr
or, this one locally which is easier to read:
    ActiveModel::MissingAttributeError in ReferentialVehicleJourneys#index
    Showing .../stif-boiv/app/views/referential_vehicle_journeys/_filters.html.slim where line #44 raised:
    missing attribute: kind
    Extracted source (around line #51):
        after_initialize do
    >     self.kind ||= :commercial
        end
        def self.nullable_attributes
    Trace of template inclusion: app/views/referential_vehicle_journeys/index.html.slim
    Rails.root: .../stif-boiv
    Application Trace | Framework Trace | Full Trace
    app/models/chouette/stop_area.rb:51:in `block in <class:StopArea>'
    app/views/referential_vehicle_journeys/_filters.html.slim:44:in `block in _app_views_referential_vehicle_journeys__filters_html_slim___131528464712770693_70134715599760'
    app/views/referential_vehicle_journeys/_filters.html.slim:1:in `_app_views_referential_vehicle_journeys__filters_html_slim___131528464712770693_70134715599760'
    app/views/referential_vehicle_journeys/index.html.slim:9:in `_app_views_referential_vehicle_journeys_index_html_slim__3124451149445015007_70134715309040'
This is because on `ReferentialVehicleJourneys#index`, the StopArea
filter makes this query:
    @all_stop_areas.select(:id, :name).order(name: :asc)
Alban added a temporary fix for the release in
c2bc391ee91cac70e726d188be97dd2323df0df2.
After a discussion with Luc, he said we only want the initial value on
the `#new` form, and we decided to take this out of the model and put it
in the form template instead.
Here, when a new `StopArea` is created, `:commercial` will be pre-filled
in the `kind` field by default. On the `#edit` page, it should show the
existing value of `kind` but not permit editing.
Refs #5817
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/stop_area.rb | 4 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 11 | 
2 files changed, 9 insertions, 6 deletions
| diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index cf2afbc73..bb8747faa 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -47,10 +47,6 @@ module Chouette      validate :parent_area_type_must_be_greater      validate :area_type_of_right_kind -    after_initialize do -      self.kind ||= :commercial -    end -      def self.nullable_attributes        [:registration_number, :street_name, :country_code, :fare_code,        :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index 9897a27ac..bb1fbe1e9 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -12,8 +12,15 @@              .col-sm-9.col-xs-7                - f.object.localized_names.each do |k, v|                  .col-md-6= f.input "localized_names[#{k}]", input_html: {value: v}, label: label_for_country(k) -                 -        = f.input :kind, as: :radio_buttons, checked: @stop_area.kind, :input_html => {:disabled => !@stop_area.new_record?}, :include_blank => false, item_wrapper_class: 'radio-inline', wrapper: :horizontal_form, disabled: !@stop_area.new_record? + +        = f.input :kind, +            as: :radio_buttons, +            checked: @stop_area.new_record? ? :commercial : @stop_area.kind, +            input_html: { disabled: !@stop_area.new_record? }, +            include_blank: false, +            item_wrapper_class: 'radio-inline', +            wrapper: :horizontal_form, +            disabled: !@stop_area.new_record?          .slave data-master="[name='stop_area[kind]']" data-value="commercial"            = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}}          - %i(non_commercial commercial).each do |kind| | 
