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.
Thanks for continue to urge me to adopt this approach.
Best wishes,
Richard
On Apr 25, 4:50 pm, Colin Law <[email protected]> wrote:
> On 25 April 2010 18:44, Hassan Schroeder <[email protected]> wrote:
>
> > On Sun, Apr 25, 2010 at 9:40 AM, Colin Law <[email protected]> wrote:
>
> >> I believe he has been trying to do that, but is that what he needs to
> >> do? Can he not just set the condition variable in the controller
> >> action? With a parameter on the link calling the action if necessary.
>
> > Not according to the examples provided -- there's a link shown to e.g.
> > /vendors/new, which would presumably lead to a POST request to a
> > `create` action, which would then redirect to a new GET request for
> > /vendor/:id `show` - which is where the OP says he wants that value
> > available.
>
> You may be right, I did not read as much into the OPs question as you
> have. I assumed that _any_ redirect to show from the create should
> include the extra link, rather than specifically a create initiated
> from the link you mention. If my interpretatioin is correct then he
> can just specify a parameter in the redirect_to :action => 'show' in
> the create action. If your interpretation is correct (which it may
> well be having re-read the original post) then I agree with your
> analysis. I would probably put something in the session for this
> case.
>
> Over to you Richard - what is your requirement in this regard.
>
> 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.