mysql - how to disable submit button after being used 1 time -
what trying following.
a user.rb can answer.rb several application.rb's created company.rb. user can answer once per unique application.
i've disabled in model can't figure out how in view.
my answer 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 applied" redirect_to root_url else flash[:alert] = "you've 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
in answer model have user_id stored. thinking @ current answer :id , check if current_user.id present in it, if disable button. haven't been able turned out successfully.
the show.html.erb looks this:
<%= form_for @answer |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 %>
if use of jquery possible in ruby, you can use .one() method
.one( events [, selector ] [, data ], handler ) [jquery 1.7+] events type: string 1 or more space-separated event types , optional namespaces, such "click" or "keydown.myplugin". selector type: string selector string filter descendants of selected elements trigger event. if selector null or omitted, event triggered when reaches selected element. data type: data passed handler in event.data when event triggered. handler type: function( event eventobject ) function execute when event triggered. value false allowed shorthand function return false.
Comments
Post a Comment