控制器动作对于button_to应该是什么样子:remote => true。rails 3 button_to:remote => true,控制器动作应该是什么样
我是新来的阿贾克斯reqs,所以我不知道我在做什么。据我所知,the:remote => true将其设置为ajax请求。
<%= button_to "Generate Code", add_code_band_path(@band), :method => :post, :remote => true %>
我现在的行动:
def add_code
@band = Band.find(params[:id])
if user_signed_in?
@code = current_user.codes.build(params[:code])
respond_to do |format|
if @code.save
format.html { redirect_to @band, notice: 'Reward was successfully created.' }
format.json { render json: @band, status: :created, location: @band }
else
format.html { render action: "show" }
format.json { render json: @band.errors, status: :unprocessable_entity }
end
end
else
redirect_to @band, :alert => "Your Not Logged In! You must be logged in to create a code"
end
end
你有什么错误? – 2012-01-18 03:59:02
没有错误,但屏幕刷新... – 2012-01-18 04:19:27