Hello all! I have two views (list_1 and list_2) that show a list of users in two different ways. In the views for these actions there is a link to edit a specific user properties (edit_user). That works fine, except that when I change the user I want to go back to the view that originated the request and not to the default list (list_1). Can anyone help me? Best regards, Hugo -- Posted via http://www.ruby-forum.com/.
I have a loop in which I cycle though a list of timesheet entries, somewhat like: @timesheet.each do |timesheet| ... end I would like to have "Up" and "Down" links in each row to reorder the list. However, this is only allowed to happen for two entries with the same date. So if there was only one entry for a particular date, there wouldn''t be any links. It''s easy enough to get the previous line''s date using an instance variable, but is there any easy way to "read ahead" and get the date for the next record? I had to resort to using javascript to populate the links when my site was based in PHP. Thanks!!
Hugo wrote:>Hello all! >I have two views (list_1 and list_2) that show a list of users in two >different ways. In the views for these actions there is a link to edit a >specific user properties (edit_user). That works fine, except that when >I change the user I want to go back to the view that originated the >request and not to the default list (list_1). > >Can anyone help me? > >Best regards, >Hugo > > >I use two methods. One to drop a ''cookie crumb'' in the session and one to redirect to the cookie crumb. In the edit_user action, save the referrer in the ''cookie crumb''. In the update redirect to the saved cookie crumb. So in usage its as simple as: def edit_user drop_cookie_crumb ... do edit stuff end def update_user ... do update stuff return_to_cookie_crumb end -- Jack Christensen jackc@hylesanderson.com
On 2/3/06, Dylan Markow <dylan@dylanmarkow.com> wrote:> I have a loop in which I cycle though a list of timesheet entries, > somewhat like: > > @timesheet.each do |timesheet| > ... > end > > I would like to have "Up" and "Down" links in each row to reorder the > list. However, this is only allowed to happen for two entries with > the same date. So if there was only one entry for a particular date, > there wouldn''t be any links. It''s easy enough to get the previous > line''s date using an instance variable, but is there any easy way to > "read ahead" and get the date for the next record? I had to resort to > using javascript to populate the links when my site was based in PHP. > > Thanks!! > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railseach_with_index is your friend. Or, alternatively, you can add your own iterator. - Rowan Rodrik -- Morality is usually taught by the immoral.
Hello Jack. Thanks for your help. I just have two questions: IF a user is using a browser with tabs (like Firefox) and opens list_1 in one tab and list_2 in another and then clicks edit_user link in both tabs what will happen? How can I distinguish the two requests so I can send the user to the correct list action? Jack Christensen wrote:> Hugo wrote: > >>Hugo >> >> >> > I use two methods. One to drop a ''cookie crumb'' in the session and one > to redirect to the cookie crumb. In the edit_user action, save the > referrer in the ''cookie crumb''. In the update redirect to the saved > cookie crumb. > > So in usage its as simple as: > def edit_user > drop_cookie_crumb > ... do edit stuff > end > > def update_user > ... do update stuff > return_to_cookie_crumb > end > > -- > Jack Christensen > jackc@hylesanderson.com-- Posted via http://www.ruby-forum.com/.
Hugo wrote:> Hello Jack. Thanks for your help. > I just have two questions: > IF a user is using a browser with tabs (like Firefox) and opens list_1 > in one tab and list_2 in another and then clicks edit_user link in both > tabs what will happen? How can I distinguish the two requests so I can > send the user to the correct list action? >Try using ''redirect_to :back'' I think this uses the browser window history. _Kevin -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich wrote: Hugo wrote: Hello Jack. Thanks for your help. I just have two questions: IF a user is using a browser with tabs (like Firefox) and opens list_1 in one tab and list_2 in another and then clicks edit_user link in both tabs what will happen? How can I distinguish the two requests so I can send the user to the correct list action? Try using ''redirect_to :back'' I think this uses the browser window history. _Kevin redirect_to :back is the same as redirect_to(request.env["HTTP_REFERER"]) according to the rails docs. The problem with redirect_to :back is you really want to go back two pages. As in list1 -> edit_user -> update_user -> list1. redirect_to :back will take you back to edit_user. As for the using cookie crumbs in the session, it will get confused with multiple tabs. In my application that has not been a problem. At first glance, I don''t see any solutions outside of storing the value somewhere on the client ala asp.net''s ViewState. But that has its own set of problems. -- Jack Christensen jackc-/SOt/BrQZzOj3I+7jmQ39gC/G2K4zDHf@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails