Ruby on Rails: Initializing instance variables with helpers in view -


I am running on the issue of some type of scope, which is called visual variables,

# sample_controller.rb class sample controller & lt; ApplicationController def TEST & End # application_controller.rb helper_method: Not Defined Display DIF Display? @ Display Return @ display = "A" and return @ display + = "one" end and # test.html. ARB & lt;% = display% & gt; & Lt;% = Display% & gt; & Lt;% = @ Display% & gt; & Lt;% = @ display.reverse% & gt;

When the sample / test is displayed, it dies with the error of "evaluating the reverse." This is surprising because the first two calls to be displayed should have been started @desplay I would have thought if is removed, the output is "AA", which indicates That the @ display instance variable is being determined by the subsidiary method, but there is no access to it in its view.

If the controller is modified (with the original view code):

  class sample controller & lt; ApplicationController def test display ending  

The output is "aa aaa aa" if I call it 2 to display it in the controller, I get it, "aaa aaa aa Aa ". It seems that the sample controller frequency variable will be modified in the call made in the controller, whereas in the view in the call, the applicationController can be modified to a frequency variable that does not have access to the view.

Is this a bug in the train or am I misunderstanding and it is for the reason of functioning due to some reason?

The context in which I went into this bug is trying to create a log-in? The application controller method that sets a user variable for the first time, and if a user is logged in, then it is correct or false. This will not work unless I add unnecessary calls in the controller before using it in the scene.

There are two display periods at the render time, in one controller and in one view. One can not access the view controller and vice versa. At the beginning of the render, all the controllers make ewer copy in copy. But at that time, @desplay is not present and has not been copied, returning the call to @my_undefined_ivar in any Ruby program - which is actually happening to you.

It can be misleading, here it is said another way. Copy the iwer from the controller to see at the beginning of the render. Therefore, changes in the ivar of the scene are not reflected in the controller ivar and vice versa. Allows you to see the given assistant a method on the controller, so that the return value of the controller can be viewed back as the return value, but the change in the controller ivar is not visible in the other, the view, the ewer.

Just use the helpful method in this case and forget about display @ in the scene.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -