1

I have a rails form that works well when creating a new model but is buggy when it comes to editing an existing one.

This is the behavior:

  • When on the edit view, the submit button will not work.

  • If I hit reload, once the edit view has rendered again, the button works fine, and I am able to submit any changes to the database.

Below is the code.

Form:

<%= form_for @client do |f| %>
    # Don't Think the problem is inside the form since it works after the reload.
    ...
    # Here is the button
    <button type="submit" value="submit" class="btn btn-success btn-lg pull-right cms-button">
        <i class="fa fa-check" aria-hidden="true"></i> Update Client
    </button>   
<% end %>

Controller:

def edit
  @client = Client.find( params[:id] )
end

def update
  @client = Client.find( params[:id] )
  if @client.update( client_params )
    flash[:notice] = "Client added succesfully"
    redirect_to( :action => 'show' )
  else
    render( 'edit)' )
  end
end

Where do I have to make changes so that the update is successful?

Jorge Cuevas
  • 755
  • 3
  • 10
  • 30
  • does this question help: http://stackoverflow.com/questions/19365809/form-submit-button-only-works-after-reload?rq=1 – xyious May 26 '16 at 20:16
  • Not exactly, but it helped motivated me to revert some HTML changes and test. The issue got fixed by doing this. If you post the answer I will mark it as accepted. – Jorge Cuevas May 26 '16 at 20:26
  • What changes did you revert in html? Would be useful for future users – Anand May 27 '16 at 04:27

1 Answers1

3

It might be an issue with the HTML that is unrelated to rails itself, this question has the same problem: Form Submit button only works after reload

Community
  • 1
  • 1
xyious
  • 1,065
  • 4
  • 13
  • 29