0

I have a form with input tag which takes a value from the user and next to that there is a link which should take that value and pass it to a method in a controller which generates an encrypted values based on that hash.

However params[:hash] which is my input does not pass input to controller. gives NULL. Please look in to my code and let me know where I am going wrong. thanks

view: 
= simple_form_for(@user, :html => {:class => 'user_form'}) do |f|
= f.input :hash, :input_html => {:class => 'span4'}
= link_to('Click to confirm key Encryption',confirm_encrypt_path(@user,:hash=>?)

controller:
def confirm_encrypt
   check = params[:hash]
   puts check # gives null value 
   MyModel.reset_authentication_pin!(current_user.id,params[:hash])
end

I Expect the puts check value should be the user entered value.

SaiT
  • 1
  • 3
  • 1
    Possible duplicate of [Adding Hash parameter in the URL Rails Routes](https://stackoverflow.com/questions/7052399/adding-hash-parameter-in-the-url-rails-routes) – DannyB Feb 05 '19 at 17:23

1 Answers1

0

It's hard to tell what's happening here because it appears you've only included a portion of the view, if you could edit your question, that might help shed some light on what else is happening.

Three things that stand out to me are:

  1. In your view you call the input :hash, but when you attempt to get the value you get params[:temp1] not params[:hash]

  2. In the link_to you include the user, but you don't include any value for the :hash. Off the top of my head, I believe you just need to do params[:hash] to successfully get the :hash value through to the controller with the way you have it.

  3. In your view you set up a simple_form_for, but it appears that you don't use a submit to get the :hash value in the controller. If you decided to go that route, you'd just have to make sure that the form is being directed to the proper controller.

coda
  • 163
  • 1
  • 9
  • Thanks for the reply regarding the params[:temp1] that was a mistype it should be params[:hash] I edited that and I did not include the value for hash because I was not sure how to pass that input( params[:hash]) in to that link_tag so i just left it with "?" lastly, I only included a part of view there are other input tags and also a submit button which on click updates all the values correctly. However this particular input hash is part of the form which i do not want to save but use this hash value to create an encrypted pin and save encrypted pin instead. – SaiT Feb 05 '19 at 17:51