On 25 April 2010 16:03, RichardOnRails
<[email protected]> wrote:
> Following up on what Bob Smith posted on 4/21 and Hassan Schroeder on
> 4/24,
> here's what I've got working:
>
> ======= app\views\vendors\show.html.erb =====
> [snip]
> <%= link_to 'Edit', edit_vendor_path(@vendor) %> |      <%# From scaffold -
> %>
> <%= link_to 'Back', vendors_path %>                             <%# From 
> scaffold -%>
>
> <%# params['show_new_expense_page'] = true %>
>
> <% if params['show_new_expense_page'] -%>
>    |
>    <%= link_to 'New Expense', '/expenses/new' %>
> <% end -%>
>
> <% params['show_new_expense_page'] = false %>
>
> ============== end ===================
>
> With the "params ... = true" line commented out, I get two links:
> Edit | Back
>
> Un-commented, I get three links as desired, and they all work:
> Edit | Back | New Expense
>
> My intention is to have the "New Expense" link visible when a
> particular link was previously clicked in the following page:
>
> ======= app\views\expenses\new.html.erb =====
> [snip]
>    <% @current_vendors =
> Vendor.find(:all, :order=>"nickname").collect { |v|
>            v.nickname + parens(v.qbname) } %>

Nothing to do with your problem but you should definitely not be doing
finds in the view, this should be in the controller.

>    <%= f.select :vendor, @current_vendors %>
>    <%   params['new_expense_page'] = true -%>
>    <%= link_to 'New
> Vendor',    :controller=>'vendors',   :action=>'new'  %>
> [snip]
> ================= end =================
>
> But the "params ... true" setting is not conveyed to the app\views
> \vendors\show.html.erb page.
>
> 1. Can this be fixed?
> 2. If not, will using session rather than params work?
> 3. Or can I access the "previous page" value in the app\views\vendors
> \show.html.erb page and test whether the previous page was app\views
> \expenses\new.html.erb?

The solution has been suggested several times already in this thread,
I will try again.
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.

Please try this and get back if you have problems, or ask for
clarification if you do not understand it (if so which bit do you not
understand).  The approach you are trying to use is not the best way.

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