我有一个问题与text_field_tag。我想重置的值当我刷新浏览器时,text_field看起来很简单问题,但是我很难找到答案。
我输入一些值后,我如何重置值为nil或空?
我的代码在
下面<%= text_field_tag 'access_code', nil,
%>
任何帮助或提示将不胜感激。
这是我的会话新页面和access_code,我在文本字段中输入是在配置中定义的。yml文件。如果我没有在文本框中输入任何访问码,我仍然会在控制器中获得上次输入的值。如何重置值?......
提前感谢!
——日志:
Started POST "/login" for 127.0.0.1 at 2015-06-09 16:14:26 +0530
I, [2015-06-09T16:14:26.368484 #6707] INFO -- : Processing by SessionsController#new as HTML
I, [2015-06-09T16:14:26.368731 #6707] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"Dw7fO0ZyO4/ZPnNknuXbt4xsLkGWlxM3rmaEYvClTDRjq0dLdVUGt84Pw2ZNBQ8Sz2x7BGZwlHCmq3EozDmoJg==", "access_code"=>"12345", "login"=>"admin", "password"=>"[FILTERED]", "commit"=>"Log in"}
D, [2015-06-09T16:14:26.372837 #6707] DEBUG -- : [1m[36mActiveRecord::SessionStore::Session Load (0.7ms)[0m [1mSELECT `sessions`.* FROM `sessions` WHERE `sessions`.`session_id` = '261e811b132a8cf574d6733a2bf5a2f4' ORDER BY `sessions`.`id` ASC LIMIT 1[0m
I, [2015-06-09T16:14:26.376843 #6707] INFO -- : checking for Mobile Device - Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.81 Safari/537.1
D, [2015-06-09T16:14:39.505665 #6707] DEBUG -- : [1m[35mSQL (1.1ms)[0m SELECT `users`.`id` AS t0_r0, `users`.`login` AS t0_r1, `users`.`email` AS t0_r2, `users`.`encrypted_password` AS t0_r3, `users`.`password_salt` AS t0_r4, `users`.`created_at` AS t0_r5, `users`.`updated_at` AS t0_r6, `users`.`remember_token` AS t0_r7, `users`.`remember_token_expires_at` AS t0_r8, `users`.`reset_password_token` AS t0_r9, `users`.`enabled` AS t0_r10, `users`.`customer_id` AS t0_r11, `users`.`status` AS t0_r12, `users`.`plain_password` AS t0_r13, `users`.`last_checked_at` AS t0_r14, `users`.`sign_in_count` AS t0_r15, `users`.`current_sign_in_at` AS t0_r16, `users`.`last_sign_in_at` AS t0_r17, `users`.`current_sign_in_ip` AS t0_r18, `users`.`last_sign_in_ip` AS t0_r19, `users`.`created_by` AS t0_r20, `users`.`failed_attempts` AS t0_r21, `users`.`disable_reason` AS t0_r22, `customers`.`id` AS t1_r0, `customers`.`name` AS t1_r1, `customers`.`customer_type` AS t1_r2, `customers`.`parent_id` AS t1_r3, `customers`.`created_at` AS t1_r4, `customers`.`updated_at` AS t1_r5, `customers`.`meta_data` AS t1_r6, `customers`.`opt_out` AS t1_r7, `customers`.`fulfilled` AS t1_r8, `customers`.`complete` AS t1_r9, `customers`.`fulfillment_issue` AS t1_r10, `customers`.`deleted_at` AS t1_r11, `customers`.`generic_bulletin` AS t1_r12, `customers`.`archived` AS t1_r13, `customers`.`vendor_rep` AS t1_r14, `customers`.`vendor_rep_email` AS t1_r15, `customers`.`vendor_rep_phone_no` AS t1_r16, `customers`.`converted_to_new_year` AS t1_r17, `customers`.`fulfillment_info` AS t1_r18, `customers`.`slug` AS t1_r19, `customers`.`start_date` AS t1_r20, `customers`.`end_date` AS t1_r21, `customers`.`bcc_on_confirmation` AS t1_r22, `customers`.`sales_tax_type` AS t1_r23, `customers`.`sales_tax_rate` AS t1_r24, `customers`.`delta` AS t1_r25, `customers`.`time_zone` AS t1_r26, `customers`.`commission_perc_req_items` AS t1_r27, `customers`.`commission_perc_optional_items` AS t1_r28, `customers`.`commission_perc_spirit_items` AS t1_r29, `customers`.`commission_perc_blended_rate` AS t1_r30, `customers`.`credit_card_processing_rate` AS t1_r31, `customers`.`monthly_service_fee` AS t1_r32, `customers`.`annual_service_fee` AS t1_r33, `customers`.`store_building_fee` AS t1_r34, `customers`.`account_setup_fee` AS t1_r35, `customers`.`fee_calculated_pre_tax` AS t1_r36, `customers`.`fee_calculated_post_tax` AS t1_r37, `customers`.`handling_fee` AS t1_r38, `customers`.`advertisement` AS t1_r39, `customers`.`payment_receiver_override` AS t1_r40, `customers`.`banner_image` AS t1_r41, `customers`.`default_payment_receiver` AS t1_r42, `customers`.`handling_fee_type` AS t1_r43, `customers`.`support_email_address` AS t1_r44, `customers`.`discount_per_order` AS t1_r45, `customers`.`discount_per_order_min_amount` AS t1_r46, `customers`.`player_number_required` AS t1_r47, `customers`.`discount_text` AS t1_r48, `customers`.`discount_max_counts` AS t1_r49, `customers`.`discount_coupon_code` AS t1_r50, `customers`.`accept_check` AS t1_r51, `customers`.`accept_credit_card` AS t1_r52, `customers`.`store_shipping_rates` AS t1_r53, `customers`.`mobile_version_enabled` AS t1_r54, `customers`.`reminder_email` AS t1_r55, `customers`.`returning_player` AS t1_r56, `customers`.`edit_order_after_closed` AS t1_r57, `customers`.`custom_text_for_receipt` AS t1_r58, `customers`.`eligibility_check_for_free_items` AS t1_r59, `customers`.`eligible_for_free_items` AS t1_r60, `customers`.`storefront_intro` AS t1_r61, `customers`.`pickup_locations` AS t1_r62, `customers`.`enable_facebook` AS t1_r63, `customers`.`allow_customer_notes_storefront` AS t1_r64, `customers`.`accept_cash` AS t1_r65, `customers`.`fb_page_id` AS t1_r66, `customers`.`league_enabled` AS t1_r67, `customers`.`status` AS t1_r68, `customers`.`agree_store_terms` AS t1_r69, `customers`.`launch_store` AS t1_r70, `customers`.`allow_shipping` AS t1_r71, `customers`.`amex_payment_method` AS t1_r72, `customers`.`copied_start_fresh_from` AS t1_r73, `customers`.`custom_message` AS t1_r74 FROM `users` LEFT OUTER JOIN `customers` ON `customers`.`id` = `users`.`customer_id` WHERE `users`.`login` = 'admin' AND `customers`.`deleted_at` IS NULL ORDER BY `users`.`id` ASC LIMIT 1
I, [2015-06-09T16:14:39.511565 #6707] INFO -- : Authentication:: Failed Login for User ID 1 Failed Login Attempts set to 2
D, [2015-06-09T16:14:39.512570 #6707] DEBUG -- : [1m[36m (0.3ms)[0m [1mBEGIN[0m
D, [2015-06-09T16:14:39.527978 #6707] DEBUG -- : [1m[35mUser Exists (0.9ms)[0m SELECT 1 AS one FROM `users` WHERE (`users`.`login` = 'admin' AND `users`.`id` != 1) LIMIT 1
D, [2015-06-09T16:14:39.534245 #6707] DEBUG -- : [1m[36mSQL (0.6ms)[0m [1mUPDATE `users` SET `failed_attempts` = 2, `updated_at` = '2015-06-09 10:44:39.514661' WHERE `users`.`id` = 1[0m
D, [2015-06-09T16:14:39.611739 #6707] DEBUG -- : [1m[35m (73.7ms)[0m COMMIT
I, [2015-06-09T16:14:39.623991 #6707] INFO -- : Rendered sessions/new.html.erb within layouts/application (5.1ms)
I, [2015-06-09T16:14:42.294270 #6707] INFO -- : Completed 200 OK in 15925ms (Views: 2680.0ms | ActiveRecord: 77.4ms)
D, [2015-06-09T16:14:42.295683 #6707] DEBUG -- : [1m[36m (0.3ms)[0m [1mBEGIN[0m
D, [2015-06-09T16:14:42.302890 #6707] DEBUG -- : [1m[35mSQL (0.5ms)[0m UPDATE `sessions` SET `data` = 'BAh7CUkiEmRvbWFpbl92ZW5kb3IGOgZFRkkiB25hBjsAVEkiEF9jc3JmX3Rvna2VuBjsARkkiMWJLV1ljRE1uUFRnWE1iQUMwK0RVcFVNQVZVWHc1NGRIQ00znMVNqeWM1Qkk9BjsARkkiEnBhc3NfYXR0ZW1wdHMGOwBGaQdJIgpmbGFzaAY7nAFR7B0kiDGRpc2NhcmQGOwBUWwZJIgplcnJvcgY7AEZJIgxmbGFzaGVzBjsAnVHsGSSIKZXJyb3IGOwBGSUM6HkFjdGl2ZVN1cHBvcnQ6OlNhZmVCdWZmZXIinAaFZb3VyIHVzZXJuYW1lIG9yIHBhc3N3b3JkIGlzIGluY29ycmVjdC4gPGJynLz5QbGVhc2UgdHJ5IGFnYWluIG9yIGNsaWNrIHRoZSBmb2xsb3dpbmcgbGlunayB0byByZXNldCB5b3VyIHBhc3N3b3JkOiA8YSBocmVmPScvZm9yZ290X3Bhnc3N3b3JkJz5Gb3Jnb3QgUGFzc3dvcmQ8L2E+Lgc7AFQ6D0BodG1sX3NhZmVUn', `updated_at` = '2015-06-09 10:44:42.298136' WHERE `sessions`.`id` = 45
D, [2015-06-09T16:14:42.363066 #6707] DEBUG -- : [1m[36m (58.4ms)[0m [1mCOMMIT[0m
这是一个js请求,那么你需要明确地使用jquery使所有文本字段html为空,因为你使用javascript
来提交表单和而不是 html
,这会导致使用redirect_to: new_session_url
的总页面刷新。所以在你的login
方法中,你必须使用类似的东西:-
def login
##save the user info
respond_to do |format|
format.js
end
end
login.js.erb
$("#login-textbox").val(" ");
或者,您可以添加特定于页面的JAVASCRIPT来清除文本框ONSUBMIT
//add this js in your page
$(document).ready(function() {
$('#btnSubmit').click(function(e) {
var isValid = true;
$('input[type="text"]').each(function() {
if ($.trim($(this).val()) == '') {
isValid = false;
$(this).css({
"border": "1px solid red",
"background": "#FFCECE"
});
}
else {
$(this).css({
"border": "",
"background": ""
});
}
});
if (isValid == false)
e.preventDefault();
else
alert('Thank you for submitting');
});
});