我的控制器創建功能如何在使用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][email protected]_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();
請將您的代碼放在代碼標籤({}符號) – ipsum 2011-04-19 13:40:55