0

I have a remote: true form in my Rails 5 app and I'd like to redirect to different pages depending on when it's used.

I've tried adding a :redirect_to virtual attribute:

<%= a.input :redirect_to, as: :hidden, input_html: { 
    value: confirmation_orders_path
} %>

And modified my model to accept this virtual attribute:

attribute :redirect_to, :string
attr_accessor :redirect_to

But I still see Unpermitted parameter: :redirect_to. What can I do to allow this param to pass?

Jeremy Thomas
  • 6,240
  • 9
  • 47
  • 92
  • 1
    Have you tried `params.require(:confirmation_orders).permit(:redirect_to)` in your controller? – NN796 Mar 22 '19 at 11:30
  • I had it in the controller prior to adding the `attribute` to the model and it threw an error so I removed it. I guess you need to have BOTH the model attribute AND and the controller permittance in order for it to work! – Jeremy Thomas Mar 22 '19 at 12:25
  • Yes, that's correct. – NN796 Mar 22 '19 at 12:32
  • redirect_to does not seem to be a reserved word, but I would still try something that doesn't look like a ruby command. Also you have declared your attribute twice. I am not very used to `attribute` so I can't say which is better... but just remove `attribute :redirect_to, :string` and keep `attr_accessor :redirect_to` and see what happens – Maxence Mar 22 '19 at 18:48
  • I believe `attribute :redirect_to, :string` is the Rails 5 way of doing it. – Jeremy Thomas Mar 22 '19 at 19:16
  • Also why not a `text_field` or `hidden_field`, `input` does not look like a regular form helper. (from regular documentation and unless it is kind of a custom method) – Maxence Mar 24 '19 at 01:39
  • I'm using simple_form and this is how they do hidden inputs – Jeremy Thomas Mar 25 '19 at 14:38

0 Answers0