我有一个轨道表单,在创建新模型时效果很好,但在编辑现有模型时却有问题。
这是行为:
-
在
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
我必须在何处进行更改才能使更新成功?
这可能是与 rails 本身无关的 HTML 问题,这个问题也有同样的问题: 表单提交按钮仅在重新加载后有效