草庐IT

省钱兄同城跑腿小程序源码uniapp前端模版源码(小程序+APP+H5)

省钱兄科技 2023-04-14 原文

开源省钱兄同城跑腿源码,目前只开源用户端V2版本部分核心模块源码提供学习研究

使用uniapp技术,提供学习使用不可商业
适配支持公众号+APP+H5+小程序,使用Hbuilder导入即可运行

#功能说明
发布跑腿 订单管理 轮播 帮我买 帮我送 同城服务 同城帮买

万能任务 公告 红包 地址管理 联系客服 系统设置 修改头像

红包列表 价格计算 协议 设置中心 登录 获取验证码等功能

定位功能 地图功能学习

# 体验方式
小程序搜索:码兄新跑腿 


# 技术栈
用户端 uniapp(vue语法)

#下载地址

省钱兄同城跑腿源码(小程序+APP+H5)uniapp前端模版源码-小程序文档类资源-CSDN下载

# 产品介绍

省钱兄同城跑腿-同城跑腿小程序源码-跑腿APP-跑腿配送服务-校园跑腿源码

<!-- 开源省钱兄同城跑腿源码,目前只开源用户端V2版本部分核心模块源码提供学习研究,使用uniapp技术,提供学习使用不可商业,商业使用请联系13895585204(同微信)授权
适配支持公众号+APP+H5+小程序,使用Hbuilder导入即可运行 -->
<template>
	<view>
		<view class="margin-lr" v-if="modelSwt == '否'">
			<view class="">
				<swiper class="swiper" autoplay="1500" :indicator-dots="true" :circular='true'
					indicator-active-color="#ffffff" indicator-color="#cccccc">
					<swiper-item class="swiper-wrap" v-for="(item,index) in bannerList" :key='index'
						style="height: 300upx;">
						<image :src="item.imageUrl" style="width: 100%;border-radius: 8upx;height: 300upx;"
							@click="goWeb(item.url)" mode="scaleToFill"></image>
					</swiper-item>
				</swiper>
			</view>

			<view class="flex justify-between align-center bg-white margin-tb padding-lr-sm radius"
				style="width: 100%;height: 100rpx;">
				<image src="../../static/image/index/xinxi.png" style="width: 126rpx;height: 30rpx;" mode=""></image>
				<view class="flex-sub margin-left-sm">
					<swiper class="swiper" autoplay="1500" :vertical='true' style="height: 40rpx;overflow: hidden;">
						<swiper-item class="" v-for="(item,index) in noticeList" :key='index' @click="goWeb1(item.url)">
							<text>{{item.title}}</text>
						</swiper-item>
					</swiper>
				</view>
			</view>
			<view>
				<view class="text-black text-xl text-bold margin-bottom">帮帮跑腿</view>
				<view class="flex justify-between flex-wrap">
					<view class="bg-video margin-tb-xs" v-for="(item,index) in classifyLsit" :key='index'
						@click="goNav(item.url)">
						<image :src="item.imageUrl" mode="" style="width: 340rpx;height: 200rpx;"></image>
						<view class="flex flex-direction justify-end"
							style="position: absolute;top: 0;padding: 30rpx;width: 100%;height: 100%;">
							<view class="text-white text-lg text-bold">{{item.name}}</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 红包 -->
			<view class="hongbao" v-if="HBShow">
				<view style="width: 52%;margin: 0 auto;position: relative;">
					<view @click="HBShow=false"
						style="position: absolute;right: -10rpx;top: -10rpx;font-size: 32rpx;font-weight: bold;">X
					</view>
					<image src="../../static/image/hb_bg.png" class="hb_img"></image>
					<image src="../../static/image/hb_btn.png" class="hb_btn" @click="takemoney()"></image>
				</view>
			</view>
		</view>

		<view class="content" v-if="modelSwt == '是'">
			<!-- #ifndef MP-WEIXIN  -->
			<view class="page-body">
				<view class="page-section page-section-gap">
					<map id="map" style="width: 100%; height: 700px;" :latitude="latitude" :longitude="longitude"
						:markers="covers" :show-location="true">
						<cover-view style="position: fixed;top: 345px;right: 30px;" @click="onToGetLocation()">
							<cover-image class="img-map1" src="../../static/image/dw.png">
							</cover-image>
						</cover-view>
					</map>
				</view>
			</view>

			<!-- #endif -->

			<!-- #ifdef MP-WEIXIN -->
			<view class="page-body">
				<view class="page-section page-section-gap">
					<map id="map" style="width: 100%; height: 700px;" :latitude="latitude" :longitude="longitude"
						:markers="covers" :show-location="true" :customCallout="customCallout">
						<cover-view style="position: fixed;bottom: 430rpx;right: 60rpx;" @click="onToGetLocation()">
							<cover-image class="img-map1" src="../../static/image/dw.png">
							</cover-image>
						</cover-view>
					</map>
				</view>
			</view>
			<!-- #endif -->


			<cover-view class="controls-title">
				<cover-view class="controls-tabs">
					<cover-view v-for="(item,index) in classifyLsit" :key="index" v-if="index<4"
						@tap="change(index,item)" class="atabs_ds">
						<cover-view>{{item.name}}</cover-view>
						<cover-view :class="{btna:count == index}"></cover-view>
					</cover-view>
				</cover-view>

				<!-- 同城服务 -->
				<cover-view class="tabs_box">
					<cover-view class="pay_tit">
						<cover-view class="pay_name">请写明{{modelDet.name }}的内容</cover-view>
						<cover-view class="pay_set">请填写您的具体要求等</cover-view>
						<cover-view class="pay_radius" @click="bindcity(4)">下单</cover-view>
					</cover-view>
				</cover-view>
			</cover-view>

			<cover-view class="hongbao" v-if="HBShow">
				<cover-view style="width: 52%;margin: 0 auto;position: relative;">
					<cover-view @click="HBShow=false"
						style="position: absolute;right: -10rpx;top: -10rpx;font-size: 32rpx;font-weight: bold;">X
					</cover-view>
					<cover-image src="../../static/image/hb_bg.png" class="hb_img"></cover-image>
					<cover-image src="../../static/image/hb_btn.png" class="hb_btn" @click="takemoney()"></cover-image>
				</cover-view>
			</cover-view>
			<cover-view v-else></cover-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				HBShow: false,
				modelSwt: "",
				modelDet: {},
				id: 0, // 使用 marker点击事件 需要填写id
				title: 'map',
				latitude: '',
				longitude: '',
				iconPath: '../../static/image/location.png',
				covers: [{
					latitude: '',
					longitude: '',
					iconPath: '../../static/image/location.png',
					width: 40,
					height: 40,
					callout: { //自定义标记点上方的气泡窗口 点击有效
						content: '当前附近骑手', //文本
						color: '#ffffff', //文字颜色
						fontSize: 10, //文本大小
						padding: 10, //附近留白
						borderRadius: 2, //边框圆角
						bgColor: '#00c16f', //背景颜色
						display: 'ALWAYS', //常显
					},
				}],
				count: "",
				list: [{
					id: 0,
					name: '帮我送'
				}, {
					id: 1,
					name: '帮我取'
				}, {
					id: 2,
					name: '同城帮买'
				}, {
					id: 3,
					name: '同城服务'
				}],
				current: 0,
				value0: '',
				value1: '',
				value2: '',
				value3: '',
				type: 'text',
				clearable: false,
				riderNumber: '',


				// 用户红包
				newUserFlag: 2,

				token: '',
				bannerList: [],
				noticeList: [],
				classifyLsit: [],

				tuiguang: '',
				tuiguangImg: '',
				arr: [],
				showModal1: true,
				invitationCode:''

			}
		},
		// 开源省钱兄同城跑腿源码,目前只开源用户端V2版本部分核心模块源码提供学习研究,使用uniapp技术,提供学习使用不可商业,商业使用请联系13895585204授权
		// 适配支持公众号+APP+H5+小程序,使用Hbuilder导入即可运行
		onLoad(option) {
			if (option.scene) {
				console.log('邀请人的码:', option.scene)
				this.$queue.setData("userByinvitationId", option.scene);
			}
			// 获取邀请码保存到本地
			if (option.invitation) {
				that.$queue.setData('userByinvitationId', option.invitation);
			}
			this.invitationCode = this.$queue.getData('invitationCode');
			this.getBannerList()
			this.getNoticeList()
			this.getZiZhi()
			let takeAddress = {
				data1: '',
				data2: '',
			}
			let closeAddress = {
				data1: '',
				data2: '',
				data3: '',
				data4: '',
				citydata: ''
			}
			uni.setStorageSync('takeAddress', takeAddress)
			uni.setStorageSync('closeAddress', closeAddress)
			if (uni.getStorageSync('disinfo')) {
				uni.removeStorageSync('disinfo')
			}
		},
		onShow() {
			// 首页是否展示地图
			this.$Request.getT('/app/common/type/275').then(res => {
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.modelSwt = res.data.value
						this.$queue.setData('modelSwt', res.data.value)
					}
				}
			});
			this.token = uni.getStorageSync('token')
			if (this.token) {
				this.getUser()
			}


			this.$Request.getT('/app/common/type/307').then(res => { //用户端骑手取消订单通知 307
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
			})
			if (this.showModal1) {
				// #ifdef MP-WEIXIN
				this.openMsg()
				// #endif
			}
		},
		onReady() {
			this.map = uni.createMapContext("map", this)
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.tuiguang,
				path: '/pages/index/index?invitation='+this.invitationCode,
				imageUrl: this.tuiguangImg,
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: this.tuiguang,
				path: '/pages/index/index?invitation='+this.invitationCode,
				imageUrl: this.tuiguangImg,
			}
		},
		methods: {
			// 分享文案和图片
			getZiZhi() {
				this.$Request.getT('/app/common/type/276').then(res => {
					if (res.code === 0) {
						this.tuiguang = res.data.value;
					}
				});
				this.$Request.getT('/app/common/type/277').then(res => {
					if (res.code === 0) {
						this.tuiguangImg = res.data.value;
					}
				});
			},
			goWeb(url) {
				console.log(url.indexOf('/pages/') !== -1)
				return
				if (url.indexOf('/pages/') !== -1) {
					uni.navigateTo({
						url
					});
				} else {
					//#ifndef H5
					uni.navigateTo({
						url: '/pages/index/webView?url=' + url
					});
					//#endif
					//#ifdef H5
					window.location.href = url;
					//#endif
				}
			},
			goWeb1(url) {
				if (url.indexOf('http') !== -1) {
					//#ifndef H5
					uni.navigateTo({
						url: '/pages/index/webView?url=' + url
					});
					//#endif
					//#ifdef H5
					window.location.href = url;
					//#endif
				}
			},
			// 跳转发布页面
			goNav(e) {
				if (this.token) {
					uni.navigateTo({
						url: e
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/register'
					})
				}

			},
			// 获取轮播图
			getBannerList() {
				this.$Request.get("/app/banner/selectBannerList?classify=1&state=1").then(res => {
					if (res.code == 0) {
						this.bannerList = res.data
					}
				});
				this.$Request.get("/app/banner/selectBannerList?classify=4&state=1").then(res => {
					if (res.code == 0) {
						this.classifyLsit = res.data
						this.modelDet = this.classifyLsit[0]
					}
				});
			},
			// 获取公告
			getNoticeList() {
				let data = {
					page: 1,
					limit: 100
				}
				this.$Request.get("/app/notice/selectNoticeList", data).then(res => {
					if (res.code == 0) {
						this.noticeList = res.data.list
					}
				});
			},

			// 获取用户当前定位
			getUser() {
				console.log('执行')
				var that = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						// console.log('成功')
						// console.log(res)
						console.log('当前位置的经度:' + res.longitude);
						console.log('当前位置的纬度:' + res.latitude);
						that.longitude = res.longitude
						that.latitude = res.latitude


						that.covers[0].longitude = res.longitude
						that.covers[0].latitude = res.latitude
						that.getAdd(that.longitude, that.latitude)
						that.getuserinfo()
					},
					fail: function(err) {
						console.log('授权失败', err)
						uni.showToast({
							title: "获取位置授权失败",
							icon: "none"
						})
					}
				});

			},
			//右下角定位按钮的点击事件
			onToGetLocation() {
				console.log('11')
				// this.	getUser() 
				// this.map.moveToLocation(); 
				let mapContext = uni.createMapContext('map');
				mapContext.moveToLocation(); //moveToLocation将地图中心移动到当前定位点,需要配合map组件的show-location使用


			},
			// 跑腿人位置
			getAdd(lng, lat) {
				this.$Request.getT('/app/indent/find5KmRider?lng=' + lng + '&lat=' + lat).then(res => {
					// console.log('```````````````', res)
					if (res.code == 0) {
						this.riderNumber = res.data.length
						if (res.data.length > 0) {
							var arr = []

							for (var i in res.data) {
								var obj = {}
								obj.latitude = res.data[i].stationLat
								obj.longitude = res.data[i].stationLng
								obj.iconPath = '../../static/image/rider.png'
								obj.width = 30
								obj.height = 30
								arr.push(obj)
							}
							this.covers[0].callout.content = '当前附近骑手' + res.data.length + '人'
							// this.covers = arr
							this.covers = [...this.covers, ...arr];
							// console.log('this.covers ', this.covers)

						}
					}
				});
			},
			change(index, item) {
				// console.log(index)
				this.modelDet = item
				this.current = index;
				this.count = index;
				console.log(this.count)
				// uni.removeStorageSync('takeAddress')
			},
			bindHelppay(index) {
				// console.log(index)
				let token = this.$queue.getData("token");
				if (token) {
					uni.navigateTo({
						url: '/pages/Helppay/Helppay'
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/register'
					})
				}

			},
			bindcity(index) {
				// console.log(index)
				let token = this.$queue.getData("token");
				if (token) {
					uni.navigateTo({
						url: this.modelDet.url
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/register'
					})
				}

			},
			bindtake(index) {
				// console.log(index)
				let token = this.$queue.getData("token");
				if (token) {
					if (this.longitude == '') {
						this.getUser()
					} else {
						uni.navigateTo({
							url: '/pages/takeaddress/takeaddress?index=' + index
						})
					}
				} else {
					uni.navigateTo({
						url: '/pages/my/register'
					})
				}


			},
			bindclose(index) {
				// console.log(index)
				let token = this.$queue.getData("token");
				if (token) {
					uni.navigateTo({
						url: '/pages/closeaddress/closeaddress?index=' + index
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/register'
					})
				}

			},
			// 获取用户信息
			getuserinfo() {
				this.$Request.getT('/app/userinfo/findUserInfoById').then(res => {
					console.log(res)
					if (res.code == 0) {
						this.newUserFlag = res.data.newUserFlag
						console.log(this.newUserFlag)
						if (this.newUserFlag == 1) {
							this.HBShow = true
						} else {
							this.HBShow = false
						}
					}
				});
			},
			// 红包
			takemoney() {
				this.$Request.getT('/app/userinfo/getNewUserRedPacket').then(res => {
					console.log(res)
					if (res.code === 0) {
						this.HBShow = false
						this.getuserinfo()
						setTimeout(function() {
							uni.navigateTo({
								url: '/pages/my/hongbao/hongbao'
							})
						}, 100)
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
						this.newUserFlag = ''
					}
				});
			},
			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										console.log(that.arr)
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal1 = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal1 = true
									}
								}
							})
						}
					}
				})
			},
		}
	}
</script>

<style>
	.content {
		width: 100%;
		position: fixed;
		top: 0upx;
		left: 0upx;
		right: 0upx;
		bottom: 0upx;

	}

	.controls-title {
		width: 90%;
		height: 370upx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0rpx;
		margin: 40upx;
		border-radius: 26upx;
		box-shadow: 0upx 30upx 40upx 0upx rgba(187, 170, 163, 0.20);
		/* #ifndef MP-WEIXIN */
		width: 90%;
		margin: 0 40rpx;
		margin-bottom: 150rpx;
		/* #endif */
	}

	/* tab选项卡 */
	.controls-tabs {
		display: flex;
		font-size: 33rpx;
		overflow-x: auto;
	}

	.atabs_ds {
		flex-grow: 1;
		text-align: center;
		height: 55rpx;
	}

	/* .tabs_box {
			display: none;
			background: #C8C7CC;
		} */

	.btna {
		background: #FF6A04;
		width: 68%;
		height: 8rpx;
		margin: 9rpx 10rpx 10rpx 29rpx;
		border-radius: 35rpx;
	}

	.tabs_box {
		/* display: none; */
	}

	.dis {
		display: block;
	}


	.controls-tabs {
		width: 100%;
		height: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 10rpx;
	}

	.box_bg {
		width: 90%;
		height: 100upx;
		background: #FFFFFF;
		margin: 0 auto;
		border-radius: 12upx;
		display: flex;
		margin-top: 20upx;
	}

	.box {
		width: 90%;
		height: 100upx;
		background: #F5F5F5;
		margin: 0 auto;
		border-radius: 12upx;
		display: flex;
		margin-top: 20upx;
	}

	.box_dian {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.box_dian cover-image {
		width: 20upx;
		height: 20upx;
	}

	.box_name {
		flex: 5;
		display: flex;
		justify-content: left;
		align-items: center;
		color: #333333;
		font-weight: 700;
		font-size: 34rpx;
	}

	.box_addres {
		flex: 5;

	}

	.add {
		color: #333333;
		font-size: 26upx;
		letter-spacing: 2upx;
		font-weight: bold;
		line-height: 50upx;
	}

	.name {
		display: inline;
		font-size: 24upx;
		color: #999999;
	}

	.number {
		display: initial;
		color: #999999;
		font-size: 24upx;
		margin-left: 30upx;
	}

	.box_image {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.icon_you {
		color: #CCCCCC !important;
	}

	/* 同城购买 */
	.pay_tit {
		width: 90%;
		margin: 0 auto;
		height: 200upx;
		position: relative;
	}

	.pay_name {
		font-size: 31rpx;
		font-weight: bold;
		width: 95%;
		margin: 0 auto;
		letter-spacing: 2upx;
	}

	.pay_set {
		color: #333333;
		font-size: 28rpx;
		width: 95%;
		margin: 0 auto;
		margin-top: 20upx;
	}

	.pay_radius {
		width: 100upx;
		height: 100upx;
		background: #FF7F00;
		color: white;
		text-align: center;
		line-height: 100upx;
		border-radius: 68upx;
		position: absolute;
		right: 20upx;

	}

	.hongbao {
		width: 100%;
		/* height: 100px; */
		/* background: #007AFF; */
		position: fixed;
		top: 24%;
		/* bottom: 50%; */
		left: 0rpx;
		right: 0rpx;
		/* display: none; */
	}

	.hb_img {
		width: 100%;
		height: 435rpx;
	}

	.hb_btn {
		width: 60%;
		height: 72rpx;
		position: absolute;
		top: 315rpx;
		left: 80rpx;
	}

	.img-map1 {
		width: 80rpx;
		height: 80rpx;
	}
</style>

有关省钱兄同城跑腿小程序源码uniapp前端模版源码(小程序+APP+H5)的更多相关文章

  1. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  2. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  3. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  4. ruby-on-rails - Rails 应用程序之间的通信 - 2

    我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此

  5. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  6. ruby-on-rails - Rails 应用程序中的 Rails : How are you using application_controller. rb 是新手吗? - 2

    刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr

  7. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  8. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  9. ruby-on-rails - 如何重命名或移动 Rails 的 README_FOR_APP - 2

    当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?

  10. ruby - 检查是否通过 require 执行或导入了 Ruby 程序 - 2

    如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby​​文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否

随机推荐