Rails提交按钮仅在重新加载视图后才起作用

时间:2016-05-26 20:09:01

标签: ruby-on-rails forms rest crud

我有一个rails模板,在创建新模型时运行良好,但在编辑现有模型时有问题。

这是行为:

  • edit视图中,提交按钮无效。

  • 如果我点击重新加载,再次呈现edit视图后,该按钮工作正常,我可以向数据库提交任何更改。

以下是代码。

形式:

<%= 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 %>

控制器:

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

我必须在哪里进行更改才能使更新成功?

1 个答案:

答案 0 :(得分:3)

HTML可能与rails本身无关,这个问题存在同样的问题:Form Submit button only works after reload

相关问题