I''ve got two entities created by scaffolding: Expense & Vendor In Expense#new there''s a form with a Vendors-drop-down and a NewVendor- button. The latter button brings up Vendor#new. The Create button in Vendor#new brings up Vendor#show with Edit & Back links. I want to append a third link conditionally to Vendor#show: if the Expense#new form led to the Vendor#show display, I want a "Return:Expense/New" link to accompany the Edit & Back links. Is there a "Rails Way" to do this? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 April 2010 16:19, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> I''ve got two entities created by scaffolding: Expense & Vendor > > In Expense#new there''s a form with a Vendors-drop-down and a NewVendor- > button. > The latter button brings up Vendor#new. > The Create button in Vendor#new brings up Vendor#show with Edit & Back > links. > > I want to append a third link conditionally to Vendor#show: if the > Expense#new form led to the Vendor#show display, I want a > "Return:Expense/New" link to accompany the Edit & Back links. > > Is there a "Rails Way" to do this?You can set a flag in the controller at the point you know that you want to show the link @show_return_link = true Then test this in the view to see whether to show the link or not <%= link_to .... if @show_return_link %> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 %> The following produced no syntax error, but it did not display the link (Vendor::@showExpenseNew == true): <% if @showExpenseNew -%> <%= link_to ''New Expense'', ''/expense/new'' %> <% end -%> The following produced a syntax error (even worse for lower-case "vendor") <% if Vendor/@showExpenseNew -%> <%= link_to ''New Expense'', ''/expense/new'' %> <% end -%> On Apr 14, 11:30 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 14 April 2010 16:19, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > I''ve got two entities created by scaffolding: Expense & Vendor > > > In Expense#new there''s a form with a Vendors-drop-down and a NewVendor- > > button. > > The latter button brings up Vendor#new. > > The Create button in Vendor#new brings up Vendor#show with Edit & Back > > links. > > > I want to append a third link conditionally to Vendor#show: if the > > Expense#new form led to the Vendor#show display, I want a > > "Return:Expense/New" link to accompany the Edit & Back links. > > > Is there a "Rails Way" to do this? > > You can set a flag in the controller at the point you know that you > want to show the link > @show_return_link = true > Then test this in the view to see whether to show the link or not > <%= link_to .... if @show_return_link %> > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 April 2010 17:50, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-debugI 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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 15 April 2010 17:50, RichardOnRails > > > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 April 2010 16:03, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 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 falseYou 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 clickedSounds good> 3. Is referenced in app\views\vendors\show.html.erb as a condition for > whether to display some linkAlso 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.rbNo 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 April 2010 16:03, RichardOnRails > > > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 April 2010 05:46, Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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''] %>Bob, I don''t understand, a variable @show_new_expense_page set in the controller will be available in the view. Colin> > > Good luck > > Bob > > On Apr 20, 1:11 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 20 April 2010 16:03, RichardOnRails >> >> >> >> <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Bob, I don''t understand, a variable @show_new_expense_page set in the > controller will be available in the view. > > ColinSet where in the controller? In a :before_filter or in show? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 April 2010 17:17, Viorel <viorelvladu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> Bob, I don''t understand, a variable @show_new_expense_page set in the >> controller will be available in the view. >> >> Colin > > Set where in the controller? In a :before_filter or in show?It doesn''t matter, either will do. Assuming that ''show'' is the action being run. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Colin, I had to work on adding authenticated users to my app, so I had to back-burner the conditional-link issue. I nevertheless would like to keep trying to learn how to do this. Maybe CSS is the way to make the link switch between visible or not depending on context. (Just my inspiration at the moment.) Also, you mentioned that I needed have my switch initialized to false, because nil will result in the same thing, so I just commented it out in VendorController. Seems to clear up one problem.> Your first attempt just above is already a class variable, as it > starts with @ so I don''t follow you here.I think @xxx defines an instance variables while @@xxx defines a class variable in Ruby. That''s what my Ruby books tell me, as does http://www.rubyist.net/~slagell/ruby/instancevars.html. It''s nice that we got a couple of other respondents. Maybe we''ll get this resolved shortly. Best wishes, Richard On Apr 20, 1:11 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 April 2010 16:03, RichardOnRails > > > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Apr-24 22:47 UTC
Re: Re: Conditionally adding a link to a form -- how?
On Sat, Apr 24, 2010 at 2:53 PM, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> I had to work on adding authenticated users to my app, so I had to > back-burner the conditional-link issue. I nevertheless would like to > keep trying to learn how to do this.You''re making this wildly overly complicated. Stick this in a view file: <% @foo = "bar" %> <% @state = false %> <%= @foo if @state %> See what appears. Change @state to true and see what appears. If the variable you''re using to eval true/false gives you different and/or unexpected results, that variable is not what you think it is. Use debug or inspect or logging to figure out why. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 April 2010 22:53, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> Hi Colin, > > I had to work on adding authenticated users to my app, so I had to > back-burner the conditional-link issue. I nevertheless would like to > keep trying to learn how to do this. Maybe CSS is the way to make the > link switch between visible or not depending on context. (Just my > inspiration at the moment.) > > Also, you mentioned that I needed have my switch initialized to > false, because nil will result in the same thing, so I just > commented it out in VendorController. Seems to clear up one problem. > >> Your first attempt just above is already a class variable, as it >> starts with @ so I don''t follow you here.Yes you are right of course, forgot to engage brain. There is no need for a class variable, an instance variable is what you want. Colin> > I think @xxx defines an instance variables while @@xxx defines a class > variable in Ruby. That''s what my Ruby books tell me, as does > http://www.rubyist.net/~slagell/ruby/instancevars.html. > > It''s nice that we got a couple of other respondents. Maybe we''ll get > this resolved shortly. > > Best wishes, > Richard > > > On Apr 20, 1:11 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 20 April 2010 16:03, RichardOnRails >> >> >> >> <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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) } %> <%= 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? Again, thanks to all of you for your past responses. I''d be grateful for any additional ideas you may offer. -- Richard On Apr 24, 6:47 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Apr 24, 2010 at 2:53 PM, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > I had to work on adding authenticated users to my app, so I had to > > back-burner the conditional-link issue. I nevertheless would like to > > keep trying to learn how to do this. > > You''re making this wildly overly complicated. > > Stick this in a view file: > > <% @foo = "bar" %> > <% @state = false %> > <%= @foo if @state %> > > See what appears. Change @state to true and see what appears. > > If the variable you''re using to eval true/false gives you different and/or > unexpected results, that variable is not what you think it is. > > Use debug or inspect or logging to figure out why. > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 April 2010 16:03, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>> forgot to engage brainThe happens to me all the time. I retired a decade ago and I often can''t remember what I did or intended five minutes ago. I''ve developed some techniques for combating this weakness, e.g.. when programming I log screen-shots of what I did and what I got as a result. It has a two-fold benefit: (1) if something goes awry, I can accurately recall what led up to the problem; and (2) if I can''t remember how to do something I "know" how to do, I can search my log mechanically to get a clue. Cheers, Richard On Apr 25, 3:45 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24 April 2010 22:53, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > Hi Colin, > > > I had to work on adding authenticated users to my app, so I had to > > back-burner the conditional-link issue. I nevertheless would like to > > keep trying to learn how to do this. Maybe CSS is the way to make the > > link switch between visible or not depending on context. (Just my > > inspiration at the moment.) > > > Also, you mentioned that I needed have my switch initialized to > > false, because nil will result in the same thing, so I just > > commented it out in VendorController. Seems to clear up one problem. > > >> Your first attempt just above is already a class variable, as it > >> starts with @ so I don''t follow you here. > > Yes you are right of course, forgot to engage brain. There is no need > for a class variable, an instance variable is what you want. > > Colin > > > > > > > I think @xxx defines an instance variables while @@xxx defines a class > > variable in Ruby. That''s what my Ruby books tell me, as does > >http://www.rubyist.net/~slagell/ruby/instancevars.html. > > > It''s nice that we got a couple of other respondents. Maybe we''ll get > > this resolved shortly. > > > Best wishes, > > Richard > > > On Apr 20, 1:11 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 20 April 2010 16:03, RichardOnRails > > >> <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. > >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think I see the cause of lack of communication between params in 1) app\views\expenses\new.html.erb; and 2) app\views\vendors\show.html.erb The are two distinct params, viz: one in an instance of app\controllers\expenses_controller.rb; the other in instance of app\controllers\vendors_controller.rb; And if I we overcome that problem, perhaps there''s an even bigger problem: my app is intended to be installed on a server, includes the database. But the app is to be users of several classes on the network. Wouldn''t the use of params fail in that case, but be ameliorated by use of sessions? Am I all wet about this? Thanks in advance, Richard On Apr 24, 6:47 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Apr 24, 2010 at 2:53 PM, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > I had to work on adding authenticated users to my app, so I had to > > back-burner the conditional-link issue. I nevertheless would like to > > keep trying to learn how to do this. > > You''re making this wildly overly complicated. > > Stick this in a view file: > > <% @foo = "bar" %> > <% @state = false %> > <%= @foo if @state %> > > See what appears. Change @state to true and see what appears. > > If the variable you''re using to eval true/false gives you different and/or > unexpected results, that variable is not what you think it is. > > Use debug or inspect or logging to figure out why. > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Apr-25 15:41 UTC
Re: Conditionally adding a link to a form -- how?
RichardOnRails wrote:>>> forgot to engage brain > The happens to me all the time. I retired a decade ago and I often > can''t remember what I did or intended five minutes ago. I''ve > developed some techniques for combating this weakness, e.g.. when > programming I log screen-shots of what I did and what I got as a > result.Can I suggest that you supplement this with automated tests and version control?> It has a two-fold benefit: (1) if something goes awry, I can > accurately recall what led up to the problem; and (2) if I can''t > remember how to do something I "know" how to do, I can search my log > mechanically to get a clue. > > Cheers, > RichardBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Apr-25 15:45 UTC
Re: Re: Conditionally adding a link to a form -- how?
On Sun, Apr 25, 2010 at 8:38 AM, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> I think I see the cause of lack of communication between params in> Am I all wet about this?Yes. I think you are totally missing how the Web works :-) The params hash represents name/value pairs passed from a client (browser, typically) to your server, either as a GET request''s query string, or as body parts of a POST request. So the life of a params hash is one request. If you want something to persist beyond that, put it in session, store it in the DB or use a hidden field in a form. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 April 2010 16:45, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 25, 2010 at 8:38 AM, RichardOnRails > <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: >> I think I see the cause of lack of communication between params in > >> Am I all wet about this? > > Yes. I think you are totally missing how the Web works :-) > > The params hash represents name/value pairs passed from a client > (browser, typically) to your server, either as a GET request''s query > string, or as body parts of a POST request. > > So the life of a params hash is one request. If you want something > to persist beyond that, put it in session, store it in the DB or use a > hidden field in a form.Or copy it into an @ variable in the controller action to make it available in the rendered view. But I believe for the OP''s problem he does not require to use params (or persistence) at all. See my previous post. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Apr-25 16:07 UTC
Re: Re: Conditionally adding a link to a form -- how?
On Sun, Apr 25, 2010 at 8:53 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Or copy it into an @ variable in the controller action to make it > available in the rendered view. But I believe for the OP''s problem he > does not require to use params (or persistence) at all. See my > previous post.My impression is that the OP is trying to set a variable in one view (and yes, that''s the wrong place to do it regardless): app\views\expenses\new.html.erb and have it show up in another: "But the "params ... true" setting is not conveyed to the app\views\vendors\show.html.erb page." Hence the issue of persistence... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 April 2010 17:07, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 25, 2010 at 8:53 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> Or copy it into an @ variable in the controller action to make it >> available in the rendered view. But I believe for the OP''s problem he >> does not require to use params (or persistence) at all. See my >> previous post. > > My impression is that the OP is trying to set a variable in one view > (and yes, that''s the wrong place to do it regardless): > > app\views\expenses\new.html.erb > > and have it show up in another: > > "But the "params ... true" setting is not conveyed to the > app\views\vendors\show.html.erb page." > > Hence the issue of persistence...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. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Apr-25 17:44 UTC
Re: Re: Conditionally adding a link to a form -- how?
On Sun, Apr 25, 2010 at 9:40 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 April 2010 18:44, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 25, 2010 at 9:40 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 25 April 2010 18:44, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sun, Apr 25, 2010 at 9:40 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Marnen,> Can I suggest that you supplement this with automated tests and version > control?Absolutely! That''s definitely on my agenda. But this (first) Rails app is intended to automate a substantial part of burden my son faces in managing his small business. So, I''m focused on getting "version 1" of this app developed and deployed to prove that "help is on the way." Using BDD and Subversion are my goals, but the learning curve for effective use is time taken from a delivery date. I just spent more than a week learning how to introduce navigation subtleties into my app. I probably left this problem for "version 2" but I was annoyed that my years of 20th Century computer-consulting skills were inadequate for the 21st Century Web. Now that I got a glimpse into handling this navigation problem, I off to work on the last functionality required before version 1 deployment: authenticated users. With thanks for your interest in my humble efforts, Richard On Apr 25, 11:41 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> RichardOnRails wrote: > >>> forgot to engage brain > > The happens to me all the time. I retired a decade ago and I often > > can''t remember what I did or intended five minutes ago. I''ve > > developed some techniques for combating this weakness, e.g.. when > > programming I log screen-shots of what I did and what I got as a > > result. > > Can I suggest that you supplement this with automated tests and version > control? > > > It has a two-fold benefit: (1) if something goes awry, I can > > accurately recall what led up to the problem; and (2) if I can''t > > remember how to do something I "know" how to do, I can search my log > > mechanically to get a clue. > > > Cheers, > > Richard > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 April 2010 13:31, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Apr-26 14:03 UTC
Re: Conditionally adding a link to a form -- how?
RichardOnRails wrote:> Hi Marnen, > >> Can I suggest that you supplement this with automated tests and version >> control? > > Absolutely! That''s definitely on my agenda. But this (first) Rails > app is intended to automate a substantial part of burden my son faces > in managing his small business. So, I''m focused on getting "version > 1" of this app developed and deployed to prove that "help is on the > way."As I''ve said before, you really must implement version control *today*. It will take at most an hour or two, and it will make version 1 easier to develop. Don''t wait another minute.> > Using BDD and Subversion are my goals,Not Subversion, please. Use Git.> but the learning curve for > effective use is time taken from a delivery date.Wrong! If you take a few minutes to sharpen the saw, you will fell the tree faster.> I just spent more > than a week learning how to introduce navigation subtleties into my > app. I probably left this problem for "version 2"Yes, you probably should have.> but I was annoyed > that my years of 20th Century computer-consulting skills were > inadequate for the 21st Century Web. >Don''t let annoyance drive you into decisions that even you know are bad.> Now that I got a glimpse into handling this navigation problem, I off > to work on the last functionality required before version 1 > deployment: authenticated users.Authlogic. Done.> > With thanks for your interest in my humble efforts, > RichardGood luck! It''s always nice to see someone seriously learning. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Yes. I think you are totally missing how the Web works :-)Funny, but oh so true!> The params hash represents name/value pairs passed from a client > (browser, typically) to your server, either as a GET request''s query > string, or as body parts of a POST request.This is definitely one of the things I haven''t gotten into my head.> put it in sessionI''m ready to add some version of an authenticated user, Authlogic, I think. That should give me a session as my repository> store it in the DBOk, I could script/generate another a model, etc for another table with CRUD methods.> hidden field in a form.I see plenty of info on this via Google, which I''ll look into in time. OK, I see several potential solutions to my problem. I''m going to suspend this issue until I complete the user''s creation and packaging a version 1 deliverable. Many thanks, Richard On Apr 25, 11:45 am, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Apr 25, 2010 at 8:38 AM, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > I think I see the cause of lack of communication between params in > > Am I all wet about this? > > Yes. I think you are totally missing how the Web works :-) > > The params hash represents name/value pairs passed from a client > (browser, typically) to your server, either as a GET request''s query > string, or as body parts of a POST request. > > So the life of a params hash is one request. If you want something > to persist beyond that, put it in session, store it in the DB or use a > hidden field in a form. > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Something is still not working as you think it is.You''re right about that, especially the practice of setting @xxx in one controller and (correctly) referencing it''s value in second (unrelated by hierarchy) controller. I think that can only work by meta-programming magic. I''m going to post a question about that at some future time when I''m not consumed by the need for a deliverable.> ... there should be no need to reset it for another action.I left the conclusion out of my description of the problem, which stated in full is: 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. leads to three links, "Edit | Back | New Expense" where there should only be two: "Edit | Back" Adding the reset clause led to correct behavior in a couple of tests, I believe. In light of your misgivngs, I thought I should remove all the params I introduced earlier. Now, the extra link appears again at times I deem to be inappropriate. So either I was wrong before or introduced another error. In any case, I can''t spend any more time on this. As I just posted Hassan, I''ll get back to this issue after I finish adding authenticated users and package a "ver. 1" deliverable.> I have just seen your next post in reply to Marnen''s suggestion on > testing. I suggest you run for cover.I''m a mere needle in a haystack comprised hundreds of millions of Americans. Finding me to inflict punishment for violating "good practices" will be inordinately difficult :-) Thanks again for you continued contribution to my Rails education. I hope you don''t find me incorrigible nor ineducable. Best wishes, Richard On Apr 26, 8:51 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 April 2010 13:31, RichardOnRails > > > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Apr-26 14:36 UTC
Re: Re: Conditionally adding a link to a form -- how?
On Mon, Apr 26, 2010 at 7:05 AM, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:>> put it in session > I''m ready to add some version of an authenticated user, Authlogic, I > think. That should give me a session as my repositoryThe "session" concept doesn''t imply "authentication" -- it''s a Rails built-in feature. And again it''s just a hash. Set a value: session["somevar"] = "somevalue" Read it anywhere: session["somevar"] That''s all there is to it. (Yes, there is a 4k limit to data stored in the default Session::CookieStore -- shouldn''t be a problem for you in this example at least. But the API docs are your friend.) HTH, and good luck, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Hassan,> The "session" concept doesn''t imply "authentication" -- it''s a Rails > built-in feature.I didn''t think that one needed an authenticated user in order to have a session. But I definitely thought one needed to have a User defined in order to have session defined. So I was surprised that "session[:symbol] = value" worked fine. The app I''m working on will be stored on a server to be accessed by perhaps 25 to 50 users on desktops connected through a LAN. Since we''re on the topic, do I have to do any thing special to ensure that each user has a distinct session inaccessible to all other users? (I''ll check the Rails'' docs later.) I am going to add Authlogic gem tomorrow, I think, so that the app can provide secure user-login. I expect Authlogic will hook-up with the already-working session mechanism. Thanks for getting me going on the session approach. I''ve just got to diagram the flow of control in my app (or maybe jot down a finite state machine) to figure out where to stick my session[:show_link]=true/false expressions. Best wishes, Richard On Apr 26, 10:36 am, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, Apr 26, 2010 at 7:05 AM, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > >> put it in session > > I''m ready to add some version of an authenticated user, Authlogic, I > > think. That should give me a session as my repository > > The "session" concept doesn''t imply "authentication" -- it''s a Rails > built-in feature. And again it''s just a hash. > > Set a value: > session["somevar"] = "somevalue" > > Read it anywhere: > > session["somevar"] > > That''s all there is to it. (Yes, there is a 4k limit to data stored in the > default Session::CookieStore -- shouldn''t be a problem for you in > this example at least. But the API docs are your friend.) > > HTH, and good luck, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
OK Marnen, your hectoring has overcome me: I got Git working with a local repository :-) BTW, if you had mentioned that Linus Torvalds was the founder of Git, I would have embraced it a lot sooner ;) But BDD will have to wait for the addition of one more feature: authenticated users. Best wishes, Richard On Apr 26, 10:03 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> RichardOnRails wrote: > > Hi Marnen, > > >> Can I suggest that you supplement this with automated tests and version > >> control? > > > Absolutely! That''s definitely on my agenda. But this (first) Rails > > app is intended to automate a substantial part of burden my son faces > > in managing his small business. So, I''m focused on getting "version > > 1" of this app developed and deployed to prove that "help is on the > > way." > > As I''ve said before, you really must implement version control *today*. > It will take at most an hour or two, and it will make version 1 easier > to develop. Don''t wait another minute. > > > > > Using BDD and Subversion are my goals, > > Not Subversion, please. Use Git. > > > but the learning curve for > > effective use is time taken from a delivery date. > > Wrong! If you take a few minutes to sharpen the saw, you will fell the > tree faster. > > > I just spent more > > than a week learning how to introduce navigation subtleties into my > > app. I probably left this problem for "version 2" > > Yes, you probably should have. > > > but I was annoyed > > that my years of 20th Century computer-consulting skills were > > inadequate for the 21st Century Web. > > Don''t let annoyance drive you into decisions that even you know are bad. > > > Now that I got a glimpse into handling this navigation problem, I off > > to work on the last functionality required before version 1 > > deployment: authenticated users. > > Authlogic. Done. > > > > > With thanks for your interest in my humble efforts, > > Richard > > Good luck! It''s always nice to see someone seriously learning. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Apr-28 12:37 UTC
Re: Conditionally adding a link to a form -- how?
RichardOnRails wrote:> OK Marnen, your hectoring has overcome me: I got Git working with a > local repository :-)Excellent! If you don''t mind one more tip: commit far more often than you think is necessary. Many little commits are often better than one big one (unless it''s one conceptual change in the big commit).> > BTW, if you had mentioned that Linus Torvalds was the founder of > Git, I would have embraced it a lot sooner ;):)> > But BDD will have to wait for the addition of one more feature: > authenticated users.Understood. That''s admittedly a bit harder to set up. But *do* do it. (Cucumber rocks!)> > Best wishes, > RichardBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> If you don''t mind one more tipOn the contrary, I very much appreciate your advice. But I''m down here in my own trench, so I have to operate on a time-table that meets my current needs. It took me hours to set Git up.)> commit far more often than you think is necessary.I''m on-board with this one, especially because it''s convenient to add a descriptor of effect of the update or the status of the app by virtue of the update.. That''s a biggie.>> But BDD will have to wait ... > Understood ... but *do* do it.I''ts on my short-list of To-Do''s> Cucumber rocks!The B''more on Rails local users group just did a nice presentation on it aimed simultaneously at Cuc-newbies and -vets. It''s short-listed also, and the presenters are friends, so I got local help should it be needed. Again, many thanks for your guidance, Richard On Apr 28, 8:37 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> RichardOnRails wrote: > > OK Marnen, your hectoring has overcome me: I got Git working with a > > local repository :-) > > Excellent! If you don''t mind one more tip: commit far more often than > you think is necessary. Many little commits are often better than one > big one (unless it''s one conceptual change in the big commit). > > > > > BTW, if you had mentioned that Linus Torvalds was the founder of > > Git, I would have embraced it a lot sooner ;) > > :) > > > > > But BDD will have to wait for the addition of one more feature: > > authenticated users. > > Understood. That''s admittedly a bit harder to set up. But *do* do it. > (Cucumber rocks!) > > > > > Best wishes, > > Richard > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-05 12:37 UTC
Re: Conditionally adding a link to a form -- how?
RichardOnRails wrote:>> If you don''t mind one more tip > On the contrary, I very much appreciate your advice. But I''m down > here in my own trench,That''s a bad sign right there. If you mean what I think you meant, it implies that you''re a bit out of touch and probably working somewhat inefficiently.> so I have to operate on a time-table that > meets my current needs.Understood, but I''m not sure you fully appreciate how much time good tools can save you.> It took me hours to set Git up.)For God''s sakes, why? It should be simple.> >> commit far more often than you think is necessary. > I''m on-board with this one, especially because it''s convenient to add > a descriptor of effect of the update or the status of the app by > virtue of the update.. That''s a biggie.Yup! Welcome to the wonderful world of version control.> >>> But BDD will have to wait ... >> Understood ... but *do* do it. > I''ts on my short-list of To-Do''s >Great!>> Cucumber rocks! > The B''more on Rails local users group just did a nice presentation on > it aimed simultaneously at Cuc-newbies and -vets. It''s short-listed > also, and the presenters are friends, so I got local help should it be > needed. >Excellent.> Again, many thanks for your guidance, > RichardYou''re welcome. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.