Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to extend surveyor_gui functionality by decorator loading ability #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update readme with decorator loading documentation
midhunkrishna committed Mar 22, 2015
commit f4c945d2f83c5e6dd9b0d298236d3ac69a659bd2
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -122,6 +122,35 @@ possible to mark certain parts of a survey as unmodifiable so that they will alw

A template library feature is pending.

## Overriding/Extending surveyor_gui functionality

Surveyor_gui is mounted as an engine. Engine model and controller classes can be extended by open classing them in the main Rails application. Open classing an Engine class redefines it for use in the main application. This is usually implemented by using the decorator pattern. (from [rails guides](http://guides.rubyonrails.org/engines.html#improving-engine-functionality))

Eg: For overriding module `SurveyfromsConrollerMethods`,

Step 1. create file `surveyforms_conroller_methods_decorator.rb` under `app/decorators/modules/surveyor_gui`
Step 2. For simple modificaions, consider `module_eval`, for complex modificaions, try `ActiveSupport::Concern`

###### Sample decorator code:
```
SurveyorGui::SurveyformsControllerMethods.module_eval do
def create
params["surveyform"]["service_category"] = params["surveyform"]["service_category"].try(:to_i)
@surveyform = Surveyform.new(surveyforms_params.merge(user_id: @current_user.nil? ? @current_user : @current_user.id))
if @surveyform.save
flash[:notice] = I18n.t('create.success')
@title = "Edit Survey"
@question_no = 0
redirect_to edit_surveyform_path(@surveyform.id)
else
render :action => 'new'
end
end
end
```

This code overrides `create` method defined in `SurveyformsControllerMethods` module.

## Test environment

If you want to try out surveyor-gui before incorporating it into an application, or contribute, clone the repository.