Try using params instead of variables. The variables lose scope when
changing between views/controllers and once that happens, the value
becomes nil. Instead of
@show_new_expanse_page = true try
params['new_expense_page'] = true

and the value will persist until used. the test for this would be
changed from

<%= link_to 'New Expense', '/expenses/new' if @show_new_expense_page
%> to
<%= link_to 'New Expense', '/expenses/new' if
params['show_new_expense_page'] %>


Good luck

Bob

On Apr 20, 1:11 pm, Colin Law <[email protected]> wrote:
> On 20 April 2010 16:03, RichardOnRails
>
>
>
> <[email protected]> wrote:
> > Hi Colin,
>
> >>> The following in app\views\vendors\show.html.erb works perfectly
> >>> <%= link_to 'New Expense', '/expenses/new' %>
>
> >>> I have the following in app\controllers\vendors_controller.rb
> >>> class VendorsController < ApplicationController
> >>>     @show_new_expense_page = true
> >>> [snip[
>
> >>> I now have  in app\views\vendors\show.html.erb
> >>> <%= link_to 'New Expense', '/expenses/new' if @show_new_expense_page %>
> >>> The foregoing link fails to be displayed
>
> >> I guess in this case that @showExpenseNew is not actually true as you 
> >> think it is.
> > You are so right!!  It is nil
>
> >> look athttp://guides.rubyonrails.org/
> > Excellent guidance; it's excellent
>
> >> My favorite is to use ruby-debug
> > I did that. It took me days to get working. I won't bore you with my
> > travails.  But knew I needed to be able to debug but I didn't want to
> > detour from getting version 1 of my app completed.  But your
> > suggestion persuaded me otherwise.
>
> > My goal is to have a variable that is persistent and which:
> > 1. Is defined somewhere and initialized to false
>
> You don't need to define it and set it to false, the code
> if variable
> is ok to use if variable is not defined - that is the same as false.
> So you only need to set it to true where you want it true.
>
> > 2. Is set to true in app\views\expenses\new.html.erb when the <%=
> > link_to 'New Vendor' ... is clicked
>
> Sounds good
>
> > 3. Is referenced in app\views\vendors\show.html.erb as a condition for
> > whether to display some link
>
> Also sounds good
>
>
>
> > My current guess is to use a session variable,  which I've got a lot
> > of hope for.  If that doesn't work,  I'll start a new thread.
>
> There should not be any need for a session variable, just set it in
> the controller and test it in the view.
>
>
>
> > Best wishes,
> > Richard
>
> > BTW, some of my failures are:
> > My first attempt to see whether a shared value would work with
> > @show_new_expense_page = true in app\controllers
> > \vendors_controller.rb
> > failed in app\views\vendors\show.html.erb
> > because @show_new_expense_page was nil,
>
> Why is it nil if you are setting in in the controller?  Are you sure
> it is executing that line in the controller.  Break there with
> ruby-debug and check.
>
> > which ruby_debug demonstated for me, thanks to you.
>
> > My second attempt changed to a class variable @show_new_expense_page
> > in both places, which resulted in a syntax error.
>
> Your first attempt just above is already a class variable, as it
> starts with @ so I don't follow you here.
>
>
>
> > My third attemp was to initialize @show_new_expense_page in
> > app\controllers\application_controller.rb
>
> No need for it in application_controller, only things that all
> controllers need go here.
>
> Colin
>
> > which led to NameError in Vendors#show
> > uninitialized class variable @@show_new_expense_page in
> > ActionView::Base::CompiledTemplates
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to