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

Testbed app raising Forbidden Attributes Error #43

Open
taiwoayanleye opened this issue Feb 4, 2015 · 6 comments
Open

Testbed app raising Forbidden Attributes Error #43

taiwoayanleye opened this issue Feb 4, 2015 · 6 comments

Comments

@taiwoayanleye
Copy link

I am trying out surveyor-gui before incorporating it into an application, and after the basic question survey was completed, attempting to go to the next section raised:

ActiveModel::ForbiddenAttributesError in SurveyorController#update

I was wondering if this was a strongparams work and couldn't find strongparams defined in the SurveyorController. I also attempted to set the strongparams, but I have no idea of the attributes defiend in the model. Which way?

@kjayma
Copy link
Owner

kjayma commented Feb 5, 2015

Strong params are a bit indirect in Surveyor and SurveyorGui. You can find them in SurveyorGui under app/models/permitted_params_decorator.rb. That file reopens the PermittedParams class which is originally defined in the Surveyor gem at app/models/permitted_params.rb.

Not sure why you might be experiencing this error. Perhaps you can provide some more information:

  1. Are you using the testbed application as-is or have you customized it any way?
  2. What versions of ruby and rails are you using?
  3. Does the error message indicate which specific attribute is causing the problem?

@taiwoayanleye
Copy link
Author

First I'm using the 'simple_form' branch of Surveyor and 'zurb' branch of SurveyorGui. No error attributes was specified only the parameters from the survey submitted were returned(I don't have the screenshot anymore). I haven't customised the testbed application. Rails version is '4.1.6', Ruby is '2.2.0'.

I tried using the SurveyorGui on another branch of my real app but I kept getting error with the simple_form version. I'm guessing Surveyor is locked for simple_form '3.1.0.rc' while SurveyorGui is locked for simple_form '3.0.2'.

Could it be beacuse I'm not using the master branches of the gems? I 've tried it too and I got this error: "undefined method `boolean_label_class=' for SimpleForm:Module (NoMethodError)"

@kjayma
Copy link
Owner

kjayma commented Feb 5, 2015

So a couple of things - the Zurb branch of SurveyorGui is a work in
progress and definitely has bugs. The simple_form branch of Surveyor also
was broken last I checked and I don't think that's changed. I prefer
Simple Form over Formtastic, but was never able to get that branch of
Surveyor to work (though I didn't put a lot of time into it). I'd avoid
the custom branches. Pull the latest surveyor_gui master from github and
go with that. Otherwise, be prepared to do some debugging on your own.
Your welcome to fork surveyor_gui and see if you can finish up the Zurb
branch and get simple_form working with Surveyor. I'd be happy to pull it
in if you get it working :)

On Thu, Feb 5, 2015 at 7:23 AM, Taiwo Ayanleye [email protected]
wrote:

First I'm using the 'simple_form' branch of Surveyor and 'zurb' branch of
SurveyorGui. No error attributes was specified only the parameters from the
survey submitted were returned(I don't have the screenshot anymore). I
haven't customised the testbed application. Rails version is '4.1.6', Ruby
is '2.2.0'.

I tried using the SurveyorGui on another branch of my real app but I kept
getting error with the simple_form version. I'm guessing Surveyor is locked
for simple_form '3.1.0.rc' while SurveyorGui is locked for simple_form
'3.0.2'.

Could it be beacuse I'm not using the master branches of the gems? I 've
tried it too and I got this error: "undefined method `boolean_label_class='
for SimpleForm:Module (NoMethodError)"


Reply to this email directly or view it on GitHub
#43 (comment).

@kjayma kjayma closed this as completed Mar 8, 2015
@EmCousin
Copy link

In Rails 4, The error is due to the params in the update method that are not permitted.

As a workaround, I'd suggest to override the update method of the surveyor_controller.rb by generating a custom controller and define private params methods permitting the different params.

To do so:

$ rails generate surveyor:custom

Then in the update method, remove the call to super, get the method's source code and define private methods to permit the params.

My code :

# [...]

def update
    #super
    question_ids_for_dependencies = (r_params || []).map{|k,v| v["question_id"] }.compact.uniq
    saved = load_and_update_response_set_with_retries

    return redirect_with_message(surveyor_finish, :notice, t('surveyor.completed_survey')) if saved && finish_params

    respond_to do |format|
      format.html do
        if @response_set.nil?
          return redirect_with_message(surveyor.available_surveys_path, :notice, t('surveyor.unable_to_find_your_responses'))
        else
          flash[:notice] = t('surveyor.unable_to_update_survey') unless saved
          redirect_to surveyor.edit_my_survey_path(anchor: anchor_from(section_params), section: section_id_from(params))
        end
      end
      format.js do
        if @response_set
          render json: @response_set.reload.all_dependencies(question_ids_for_dependencies)
        else
          render text: "No response set #{response_set_code_params}",
          status: 404
        end
      end
    end
  end

# [...] [And in the custom controller : ]

 private
    def r_params
      return unless params[:r]
      params.require(:r).permit!
    end

    def section_params
      return unless params[:section]
      params.require(:section).permit!
    end

    def finish_params
      return unless params[:finish]
      params.require(:finish)
    end

    def response_set_code_params
      return unless params[:response_set_code]
      params.require(:response_set_code).permit!
    end

# [...]

PS : sorry for my English. And feel free to propose improvements to this workaround, because I'm not sure I've found the optimal solution yet ;)

@lyralyra
Copy link

lyralyra commented Apr 2, 2015

Hi, I have the same error appearing when I try to preview my survey, after one section I get the Forbidden Attributes Error.
When I was using surveyor_gui 0.1.2, EmCousin's workaround worked, but now that I'm getting surveyor_gui from the master it doesn't work anymore. I am not very familiar with ruby on rails, so I have a hard time understanding what everything does.
Any idea what might be the problem?

@kjayma
Copy link
Owner

kjayma commented Apr 5, 2015

Hey guys, I'll take another look, but would one of you be able to specify a test case that I can try off the master branch? What conditions are creating this error? Thanks

@kjayma kjayma reopened this Apr 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants