Commit 88beabe7de01a091529c228c55a62f465f9a2f7c
Committed by
Diego Camarinha
1 parent
b7e10d2d
Exists in
colab
and in
4 other branches
Public parameter on creating and editing reading group / configuration
Signed off by: Pedro Scocco <pedroscocco@gmail.com>
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
app/controllers/kalibro_configurations_controller.rb
| @@ -7,7 +7,6 @@ class KalibroConfigurationsController < ApplicationController | @@ -7,7 +7,6 @@ class KalibroConfigurationsController < ApplicationController | ||
| 7 | # GET /kalibro_configurations/new | 7 | # GET /kalibro_configurations/new |
| 8 | def new | 8 | def new |
| 9 | @kalibro_configuration = KalibroConfiguration.new | 9 | @kalibro_configuration = KalibroConfiguration.new |
| 10 | - @attributes = @kalibro_configuration.attributes | ||
| 11 | end | 10 | end |
| 12 | 11 | ||
| 13 | # GET /kalibro_configurations | 12 | # GET /kalibro_configurations |
| @@ -41,10 +40,10 @@ class KalibroConfigurationsController < ApplicationController | @@ -41,10 +40,10 @@ class KalibroConfigurationsController < ApplicationController | ||
| 41 | @attributes = @kalibro_configuration.attributes | 40 | @attributes = @kalibro_configuration.attributes |
| 42 | end | 41 | end |
| 43 | 42 | ||
| 44 | - | ||
| 45 | def update | 43 | def update |
| 46 | set_kalibro_configuration | 44 | set_kalibro_configuration |
| 47 | if @kalibro_configuration.update(kalibro_configuration_params) | 45 | if @kalibro_configuration.update(kalibro_configuration_params) |
| 46 | + @kalibro_configuration.attributes.update(public: attributes_params) | ||
| 48 | redirect_to(kalibro_configuration_path(@kalibro_configuration.id)) | 47 | redirect_to(kalibro_configuration_path(@kalibro_configuration.id)) |
| 49 | else | 48 | else |
| 50 | render "edit" | 49 | render "edit" |
| @@ -76,10 +75,14 @@ class KalibroConfigurationsController < ApplicationController | @@ -76,10 +75,14 @@ class KalibroConfigurationsController < ApplicationController | ||
| 76 | params[:kalibro_configuration] | 75 | params[:kalibro_configuration] |
| 77 | end | 76 | end |
| 78 | 77 | ||
| 78 | + def attributes_params | ||
| 79 | + params[:attributes][:public] == "1" | ||
| 80 | + end | ||
| 81 | + | ||
| 79 | # Extracted code from create action | 82 | # Extracted code from create action |
| 80 | def create_and_redir(format) | 83 | def create_and_redir(format) |
| 81 | if @kalibro_configuration.save | 84 | if @kalibro_configuration.save |
| 82 | - current_user.kalibro_configuration_attributes.create kalibro_configuration_id: @kalibro_configuration.id | 85 | + current_user.kalibro_configuration_attributes.create(kalibro_configuration_id: @kalibro_configuration.id, public: attributes_params) |
| 83 | 86 | ||
| 84 | format.html { redirect_to kalibro_configuration_path(@kalibro_configuration.id), notice: t('successfully_created', :record => @kalibro_configuration.model_name.human) } | 87 | format.html { redirect_to kalibro_configuration_path(@kalibro_configuration.id), notice: t('successfully_created', :record => @kalibro_configuration.model_name.human) } |
| 85 | format.json { render action: 'show', status: :created, location: @kalibro_configuration } | 88 | format.json { render action: 'show', status: :created, location: @kalibro_configuration } |
app/controllers/reading_groups_controller.rb
| @@ -38,6 +38,7 @@ class ReadingGroupsController < ApplicationController | @@ -38,6 +38,7 @@ class ReadingGroupsController < ApplicationController | ||
| 38 | 38 | ||
| 39 | def update | 39 | def update |
| 40 | if @reading_group.update(reading_group_params) | 40 | if @reading_group.update(reading_group_params) |
| 41 | + @reading_group.attributes.update(public: attributes_params) | ||
| 41 | redirect_to(reading_group_path(@reading_group.id)) | 42 | redirect_to(reading_group_path(@reading_group.id)) |
| 42 | else | 43 | else |
| 43 | render "edit" | 44 | render "edit" |
| @@ -67,11 +68,15 @@ class ReadingGroupsController < ApplicationController | @@ -67,11 +68,15 @@ class ReadingGroupsController < ApplicationController | ||
| 67 | params[:reading_group][:name].strip! | 68 | params[:reading_group][:name].strip! |
| 68 | params[:reading_group] | 69 | params[:reading_group] |
| 69 | end | 70 | end |
| 71 | + | ||
| 72 | + def attributes_params | ||
| 73 | + params[:attributes][:public] == "1" | ||
| 74 | + end | ||
| 70 | 75 | ||
| 71 | # Extracted code from create action | 76 | # Extracted code from create action |
| 72 | def create_and_redir(format) | 77 | def create_and_redir(format) |
| 73 | if @reading_group.save | 78 | if @reading_group.save |
| 74 | - current_user.reading_group_attributes.create reading_group_id: @reading_group.id | 79 | + current_user.reading_group_attributes.create(reading_group_id: @reading_group.id, public: attributes_params) |
| 75 | 80 | ||
| 76 | format.html { redirect_to reading_group_path(@reading_group.id), notice: t('successfully_created', :record => t(@reading_group.class)) } | 81 | format.html { redirect_to reading_group_path(@reading_group.id), notice: t('successfully_created', :record => t(@reading_group.class)) } |
| 77 | format.json { render action: 'show', status: :created, location: @reading_group } | 82 | format.json { render action: 'show', status: :created, location: @reading_group } |