Passing a model attribute to a Rails view using redirect_to

I am trying to pass a model attribute to a view, after successfully setting it to a new value from within the action in my controller. But this variable is always zero when it falls into the view, so I can not use it to conditionally display material. I must add that this attribute is not a field in the database. What am I missing / doing wrong?

Here is the code in my model:

attr_accessor :mode

#getter
def mode
 @mode
end

#setter
def mode=(val)
 @mode = val
end

... in the controller:

@report.mode = "t"
redirect_to edit_report_path(@report)

... and in my opinion:

<%= build_report(@report.mode) %>

... but this helper method never gets the variable that I just set in the controller. This is zero. What gives? Clearly, I missed something basic, because it looks like it should be simple. Any insight would be greatly appreciated. Thanks.

+5
3

edit_report_path URL @report .

redirect_to URL-. edit, , , . - , , , -db.

. : render , - @report .

@report.mode = "t"
render :action => edit and return

mode .

+3

redirect_to. - , . , @report.mode = "t", . , .

, <%= build_report(@report.mode) %> edit_report.html.erb, , "", . , report.mode URL-, :

 build_report(@report.mode, :mode => "t")
+2

redirect_to; , URL-. , .

0

All Articles