如何使用Ajax和Jquery在Rails 3中显示Flash错误消息?
|
我的控制器创建功能是
def create
@group = Group.new(params[:group])
@group.company=current_user.company
respond_to do |format|
if @group.save
format.html { redirect_to(@group, :notice => \'Group was successfully created.\') }
format.js
else
flash.now[:error]=@group.errors.full_messages
format.html { render :nothing => true }
format.js
end
end
end
create.js.erb文件是
$(\'<%= escape_javascript(render(:partial => @group))%>\').appendTo(\'#groups\');
$(\"#new_group\")[0].reset();
没有找到相关结果
已邀请:
2 个回复
蕉衫
有了这个助手
与已经在布局中设置的Flash div配合使用时效果很好
希望这可以帮助
豹芜澈
在js.erb文件中为Flash设置一个JavaScript变量。然后检查一个值并使用javascript更新\“ flash-error \” div。它可能看起来像这样: