Ruby on Rails, :notice -
i using file uploader illustration ruby on rail.
i have piece of code in controller. , need have :notice parameter somewhere, when file uploaded notice "you have uploaded file", if there error "something went wrong"
def create p_attr=params[:upload] p_attr[:arraydb] = params[:upload][:upload].first if params[:upload][:upload].class == array @upload = upload.new(p_attr) respond_to |format| if @upload.save @upload.update_attributes(:user_id => current_user.id) format.html { render :json => [@upload.to_jq_upload].to_json, :layout => false } format.json { render json: [@upload.to_jq_upload].to_json, status: :created, location: @upload } else format.html { render action 'new' } format.json{ render json: {name:(@upload.upload_file_name).split(".").first ,error: @upload.errors.messages[:upload_file_name]}, :status =>422} end end end so, need this:
format.html { redirect_to(@upload, :notice => "lalalalalala") } but have no thought how integrate :notice code
thanks in advance.
this how 'integrate' notice responses
def create p_attr=params[:upload] p_attr[:arraydb] = params[:upload][:upload].first if params[:upload][:upload].class == array @upload = upload.new(p_attr) respond_to |format| if @upload.save @upload.update_attributes(:user_id => current_user.id) format.html { redirect_to(@upload, :notice => "success") } format.json { render json: [@upload.to_jq_upload].to_json, status: :created, location: @upload } else format.html { render action 'new', :notice => "failed" } format.json{ render json: {name:(@upload.upload_file_name).split(".").first ,error: @upload.errors.messages[:upload_file_name]}, :status =>422} end end end ruby-on-rails
No comments:
Post a Comment