Rendering subnav for GET and POST to the same page

42 views
Skip to first unread message

sange...@gmail.com

unread,
Sep 16, 2013, 2:18:44 PM9/16/13
to simple-n...@googlegroups.com
I have a page that needs to load the same subnav if the page is loaded with either GET or POST. I know that I can use the :method option to specify which one to look for, but I can't seem to get it to respond to both GET and POST. The closes I've gotten to was 

    primary.item :account, 'Account', accounts_path, :method => [:get, :post] do |account|
        ....
    end

which then uses POST to load that page when the Account nav item is clicked. How can I achieve this?

Andi Schacke

unread,
Sep 16, 2013, 2:52:57 PM9/16/13
to simple-n...@googlegroups.com
Hi

the :method param "mimics" the :method param from the rails link_to helper. It can be used to have a "rails style" delete link by passing in :method => :delete. It has nothing to do with how or which subnav element is loaded or displayed. To have control over which subnav is selected, you can either use the :auto_highlight option (which is turned on by default) which makes a subnav active if its parent url matches the current_url. Or you can use :highlights_on with a regexp to specify when a navigation item should be considered active. 

I hope I did not misunderstand your question.

Andi


--
You received this message because you are subscribed to the Google Groups "simple-navigation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-navigat...@googlegroups.com.
To post to this group, send email to simple-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-navigation.
For more options, visit https://groups.google.com/groups/opt_out.

sange...@gmail.com

unread,
Sep 16, 2013, 3:54:28 PM9/16/13
to simple-n...@googlegroups.com
Hi Andi - thanks for the quick response. I see that I was wrong about the :method parameter - that makes sense. The issue that I'm having is that the subnav appears when the page is loaded via GET, but not when the page is loaded via POST. Here's a bit more detail about my situation.

I have the following two routes that both load the same page:
  get "accounts" => "accounts#overview"
  post "accounts" => "accounts#overview"

My navigation config is set as so:
    primary.item :account, 'Account', accounts_path do |account|
      account.item :profile, 'Profile', accounts_profile_path
      account.item :letters, 'Letters', accounts_letters_path
      account.item :payment_methods, 'Payment Methods', '/accounts/payment-methods'
      account.item :pending, 'Pending', accounts_pending_path
      account.item :cancel, 'Cancel', accounts_cancel_path, :unless => Proc.new { @account.blank? || !@account.is_cancelled? }
      account.item :refund, 'Refund', accounts_refund_path, :unless => Proc.new { @account.blank? || !@account.is_cancelled? }
    end

When I simply click on the "Account" nav item, the subnav loads properly. I also have a search that lists accounts into a table and POSTs to the Account (accounts#overview) page. The reason for this is because I need to store the account id of the selected account in a session variable. Do you have any idea why the subnav would not load when POST is used?

Andi Schacke

unread,
Sep 18, 2013, 2:24:59 PM9/18/13
to simple-n...@googlegroups.com
Hi Alec,

is your problem linked to this issue? https://github.com/andi/simple-navigation/issues/49

sange...@gmail.com

unread,
Sep 20, 2013, 4:52:33 PM9/20/13
to simple-n...@googlegroups.com
There certainly seem to be some similarities. I'll try implementing some of those workarounds and will follow up. Thanks.
Reply all
Reply to author
Forward
0 new messages