简体   繁体   中英

Ruby on Rails: button_to uses absolute path, but I need relative

This is my first rails project and first rails post, so I might have trouble expressing myself. I've looked around but couldn't find the answer to something I figured would be simple.

The problem is that I have a rails app that presents a button to the user, and the form action has a complete path starting with http://, even when the user is using SSL, so if they click the button they see a silly warning about the data being unencryped. I want the form action URL to start with /... Here's the code (HAML) that generates the button:

%li= button_to "Pay by Mail", mail_in_payment_new_org_contact_student_application_app_fee_payment_url(@org, current_user.contact, current_application), :method => "get"

Unfortunately, I'm diving into a project and a language with which I am unfamiliar, I've also never seen HAML before. I don't understand completely this resource: mail_in_payment_new_org_contact_student_application_app_fee_payment, nor do I understand how rails generates the URL based on it.

Any info would be really helpful.

Thank you very much.

Use

mail_in_payment_new_org_contact_student_application_app_fee_payment_path

instead of

mail_in_payment_new_org_contact_student_application_app_fee_payment_url

In short, the _url helper is absolute, _path is relative. You can read about them here . If you post the contents of config/routes.rb then I'll take a stab at explaining what that helper method is composed of.

mail_in_payment_new_org_contact_student_application_app_fee_payment_url(@org, current_user.contact, current_application)

is a Rails helper that generates a full url. If you would like a relative Url use 'path' unstead of 'url'

mail_in_payment_new_org_contact_student_application_app_fee_payment_path(@org, current_user.contact, current_application)

The details of what is going on is buried deep but it is based on your config/routes.rb file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM