Jump to content

The ultimate community for Ruby on Rails developers.


Photo

How access an instance variable in Edit from the Update method?

CRUD

  • Please log in to reply
2 replies to this topic

#1 Charlie

Charlie

    Dispatcher

  • Members
  • 34 posts

Posted 15 November 2016 - 06:47 PM

In the Edit method, the @tab variable was set to a variable that the user click to edit. However, in the Update method, I need to access this variable to set the correct form again if there is a error submitting the form. How do I access the instance variable in another method?



#2 Ohm

Ohm

    Driver

  • Moderators
  • 529 posts
  • LocationCopenhagen

Posted 15 November 2016 - 07:21 PM

The user will need to submit this, in the form. This can of course be a hidden value. You'd then be able to access it through the params object.


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#3 Charlie

Charlie

    Dispatcher

  • Members
  • 34 posts

Posted 15 November 2016 - 08:07 PM

Okay, in  the relationship edit form, I have this.

<%= f.hidden_field :tab_name, {:value => "relationships"} %>

And in the profiles_controller update medthod, I have:

@tab_name = params[:tab_name]

However, the value in the params[:tab_name} is nill. I don't think I'm doing this right. 







Also tagged with one or more of these keywords: CRUD

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users