On 26 April 2010 13:31, RichardOnRails
<[email protected]> wrote:
> Hi Colin,
>
>> In the _controller_ method that is rendering the page that has the
>> conditional link displayed set a variable
>> @show_new_expense_page = true
>> at the point in the code where you know that you wish to show the link.
>> In the view then just use if @show_new_expense_page on the link display.
> ===============
> Colin
> You're right.  I didn't [fully] understand your advice.
> Specifically,  I didn't take note of:
> "at the point in the code where you know that you wish to show the
> link".
>
> Now that I do,  the short answer is IT WORKS!!  But why, when I need
> to set a variable in one controller and access a variable of the same
> name in a DIFFERENT controller?  Following your advice,
>
> I wrote:
> 1. Set @show_new_expense_page = true in
> app\controllers\expenses_controller.rb#new
>
> 2. Reference @show_new_expense_page in
> app\controllers\vendors_controller.rb#show
>
> This approach works:
> when I click "New Expense" link in app\views\expenses\new.html.erb and
> then click Create in app\views\expenses\new.html.erb,
> I then see the following links displayed:
> Edit | Back | New Expense
>
> But, there's a glitch: I need to reset �...@show_new_expense_page to
> false
> after exiting app\views\expenses\new.html.erb by any of the six links
> in it:
> Home   Vendor   Expense   Edit | Back | New Expense
>
> Failure to employ this reset leads to, e.g.
> clicking "New Expense" in app\views\expenses\new.html.erb,
> clicking "Vendor" in app\views\expenses\new.html.erb
> clicking "Show" on any of the vendors displayed in app\views\vendors
> \index.html.erb.
>
> But the following ameliorates this problem::
> === app\controllers\vendors_controller.rb ===
> class VendorsController < ApplicationController
> [snip]
>  def index
>   �...@vendors = Vendor.all
>   �...@show_new_expense_page = false
> [snip]
>
> Maybe another navigation will, over time, reveal another weakness.
> But armed with this new understanding, acquired from you, will see me
> over any such hurdles.

Something is still not working as you think it is.  An @ variable set
in a controller action only has life into the rendered view from that
action, there should be no need to reset it for another action.  I
suggest you use ruby-debug (look at the rails guide on debugging,
google rails guides if necessary) and break into you actions and views
and work out what is going on.  Also study the log file to see exactly
what is happening.

I have just seen your next post in reply to Marnen's suggestion on
testing.  I suggest you run for cover.

Colin

-- 
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