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 at http://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 2. Is set to true in app\views\expenses\new.html.erb when the <%= link_to 'New Vendor' ... is clicked 3. Is referenced in app\views\vendors\show.html.erb as a condition for whether to display some link 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. 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, 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. My third attemp was to initialize @show_new_expense_page in app\controllers\application_controller.rb which led to NameError in Vendors#show uninitialized class variable @@show_new_expense_page in ActionView::Base::CompiledTemplates On Apr 16, 3:33 am, Colin Law <[email protected]> wrote: > On 15 April 2010 17:50, RichardOnRails > > > > <[email protected]> wrote: > > Hi Colin, > > > Thank you for your quick response: > > > I got the link I wanted working perfectly, but not the conditional > > part, which would be "icing on the cake." Following are the gory > > details. If you can spot how I can be rescued from my fumbling, I'd > > be most appreciative. > > > Best wishes, > > Richard > > > The following in app\views\vendors\show.html.erb works perfectly, but > > it's displayed unconditionally: > > <%= link_to 'New Expense', '/expenses/new' %> > > (A verticule separator from preceding links also displays perfectly, > > by also is displayed unconditionally.) > > > The following produced no syntax error, but it did not display the > > link (Vendor::@showExpenseNew == true): > > <%= @showExpenseNew ? (link_to 'New Expense', '/expense/new') : "" %> > > > The following produced no syntax error, but did not display the link > > (Vendor::@showExpenseNew == true): > > <%= link_to 'New Expense', '/expense/new' if @showExpenseNew %> > > Firstly it is conventional in rails to use underscore form for > variables (show_expense_new), though this would not cause the problem > you are seeing. If you have a look at the rails guide on debugging > (http://guides.rubyonrails.org/) you will find techniques to help when > you have this sort of problem. My favourite is to use ruby-debug to > break into the code at the point where things are not working in order > to inspect the data. I guess in this case that @showExpenseNew is not > actually true as you think it is. The simplest technique is just to > display the variable in the view and see what it's value is. > > If you are getting nowhere post the code where you set it to true. > > By the way it is generally considered good practice on the list to > insert your comments at appropriate point in the preceding email as it > makes it easier to follow the thread. > > 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 > 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.

