我的控制器创建功能是
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
Run Code Online (Sandbox Code Playgroud)
create.js.erb文件是
$('<%= escape_javascript(render(:partial => @group))%>').appendTo('#groups');
$("#new_group")[0].reset();
Run Code Online (Sandbox Code Playgroud) 我的控制器是:
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
Run Code Online (Sandbox Code Playgroud)
create.js.erb是:
$('<%= escape_javascript(render(:partial => @group))%>').appendTo('#groups');
$("#new_group")[0].reset();
Run Code Online (Sandbox Code Playgroud)