gpt4 book ai didi

mysql - 如何在使用1次后禁用提交按钮

转载 作者:行者123 更新时间:2023-11-30 00:07:00 25 4
gpt4 key购买 nike

我正在尝试做的事情如下。

一个user.rb可以answer.rbcompany.rb创建的多个application.rb>。然而,用户对于每个唯一的应用程序只能回答一次。

我已经在模型中禁用了此功能,但不知道如何在 View 中执行此操作。

我的答案 Controller :

class AnswersController < ApplicationController
before_action :authenticate_user!

def show
@application = Application.find(params[:id])
@answer = Answer.new
end


def create
@answer = Answer.new(answer_params.merge(:user_id => current_user.id))
if @answer.save
flash[:notice] = "You've successfully applied"
redirect_to root_url
else
flash[:alert] = "You've already applied"
redirect_to root_url
end
end

private

def answer_params
params.require(:answer).permit(:answer_1, :answer_2, :answer_3, :application_id)
end
end

在答案模型中,我存储了一个 user_id 。现在我的想法是,我们查看当前的答案:id 并检查其中是否存在 current_user.id,如果存在,我们禁用该按钮。但我没能做任何成功的事情。

show.html.erb 看起来像这样:

<%= form_for @answer do |f| %>
<%= f.hidden_field :application_id, value: @application.id %>

<p>Question 1: <%= @application.question_1 %></p>
<%= f.text_area :answer_1 %>

.......

<%= f.submit "Submit" %>

<% end %>

最佳答案

如果可以在 Ruby 中使用 jQuery,you can use the .one() method

.one( events [, selector ] [, data ], handler )                [jQuery 1.7+]

events
Type: String
One or more space-separated event types and optional namespaces, such as "click"
or "keydown.myPlugin".
selector
Type: String
A selector string to filter the descendants of the selected elements that trigger
the event. If the selector is null or omitted, the event is always triggered when
it reaches the selected element.
data
Type: Anything
Data to be passed to the handler in event.data when an event is triggered.
handler
Type: Function( Event eventObject )
A function to execute when the event is triggered. The value false is also allowed as
a shorthand for a function that simply does return false.

关于mysql - 如何在使用1次后禁用提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24447656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com