我来自PHP开发,我正在尝试学习Ruby on Rails.我想知道插入页眉和页脚的最佳做法是什么?通常在PHP中我会做include('header.php');,然后include('footer.php');
现在我正在尝试学习Ruby on Rails并试图了解我应该如何或在哪里放置这些页眉/页脚文件?
我创建了一个新的应用程序
rails new new_app
Run Code Online (Sandbox Code Playgroud)
然后我生成了一个新的控制器
rails generate controller SignUp
Run Code Online (Sandbox Code Playgroud)
这创建了一些文件和文件夹.我在新new_app/views/sign_up文件夹中开发了一些HTML ,但我想在此页面和将来的页面中包含页眉和页脚.我应该在哪里有这些文件?在同一个文件夹中?或者在默认文件夹下new_app/views/layouts?此外,如何在创建文件后立即包含文件?
我是ruby on rails开发的新手,我想从专家那里获得一些知识!谢谢!
为什么当我使用 URL 中的正确 id 刷新页面时,router.query 为空,但当我通过 导航到该页面时,它却有效?
说我有/pages/[user]/index.js
<Link
href="/[user]/media/[mediaId]"
as={`/${username}/media/${post.id}`}
>
Run Code Online (Sandbox Code Playgroud)
这个链接带我去localhost:3000/testuser/media/some-id
然后在/pages/[user]/media/[mediaId].js中
const MediaPage = () => {
const [post, setPost] = useState([]);
const router = useRouter();
const { mediaId } = router.query;
useEffect(() => {
router.prefetch("/");
}, []);
useEffect(() => {
if (!mediaId) return null;
getPostImage();
async function getPostImage() {
try {
const { data } = await API.graphql({
query: postById,
variables: {
id: mediaId,
},
});
setPost(data.postById.items[0]);
} catch (err) {
console.log("error getPostImage", …Run Code Online (Sandbox Code Playgroud) 我收到一个错误:
SQLite3::SQLException: no such column: ideas.list_id:
SELECT "ideas".* FROM "ideas"
WHERE "ideas"."list_id" = 2
Run Code Online (Sandbox Code Playgroud)
但我补充道
t.integer :list_id
到我的数据库迁移文件:
class CreateIdeas < ActiveRecord::Migration
def change
create_table :ideas do |t|
t.string :name
t.text :description
t.string :picture
t.timestamps
end
add_foreign_key :ideas, :lists
end
end
Run Code Online (Sandbox Code Playgroud)
这给了我这个:
class CreateIdeas < ActiveRecord::Migration
def change
create_table :ideas do |t|
t.string :name
t.text :description
t.string :picture
t.integer :list_id
t.timestamps
end
add_foreign_key :ideas, :lists
end
end
Run Code Online (Sandbox Code Playgroud)
然后我输入
rake db:migrate
Run Code Online (Sandbox Code Playgroud)
知道为什么我会收到一个错误,说没有列?我还是RoR的新人.我是否必须以其他方式添加列?
谢谢
ruby migration ruby-on-rails rails-migrations ruby-on-rails-3
看起来我已经设置了,我使用postgres我的database.yml,我可以用pgadmin III连接数据库,但是当我尝试使用psql命令测试什么版本时,它说是无法识别?知道我应该做什么吗?
我正在使用Windows并使用Ruby on Rails的命令提示符.使用随EnterpriseDB一键安装程序安装的PostgreSQL 9.2.
知道为什么会这样吗?我通常会认为Chrome会对代码更宽容吗?
$(document).keypress(function(e) {
if(e.keyCode == 39) rightImage();
if(e.keyCode == 37) leftImage();
});
Run Code Online (Sandbox Code Playgroud)
这就是我的按键是什么样的.我错过了什么吗?右图(); 和leftImage(); 因为我在其他地方也使用这些功能,所以应该起作用的功能
谢谢您的帮助!
我只是将我的本机应用程序升级到 0.62.0,现在我的应用程序不断收到此警告标志
ReactNativeFiberHostComponent: Calling `getNode()` on the ref of an Animated component
is no longer necessary. You can now directly use the ref instead.
This method will be removed in a future release.
Run Code Online (Sandbox Code Playgroud)
我不确定为什么会出现这个问题?有人可以解释一下吗?
我也看到堆栈
ref.getNode |
createAnimatedComponent.js:129:20
SafeView#_updateMeasurements | index.js:192:14
SafeView#componentDidUpdate | index.js:154:9
Run Code Online (Sandbox Code Playgroud)
更新
我相信这可能来自 react-navigation 的 SafeAreaView
有人可以帮助我,为什么在我尝试连接数据库时发生这种情况或者rails s?
在我的pg_hba.conf文件中,我有这个:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication Andrew trust
#host replication Andrew 127.0.0.1/32 trust
#host replication Andrew ::1/128 trust
local all all md5
Run Code Online (Sandbox Code Playgroud)
也许我做错了?
谢谢
我正在使用带有S3和载波的dropzone.我可以通过谷歌浏览器上传图片,但我无法使用Safari,这很奇怪.
这是我的表格
= nested_form_for @trip, html: { multipart: true, id: 'fileupload', class: 'directUpload', data: { 'form-data' => (@s3_direct_post.fields), 'url' => @s3_direct_post.url, 'host' => URI.parse(@s3_direct_post.url).host } } do |f|
.dropzone#imageUpload
= f.simple_fields_for :trip_images, TripImage.new, child_index: TripImage.new.object_id do |ff|
= ff.file_field :photo, class: 'hide form-fields'
= f.button :submit, id: "submit-data"
Run Code Online (Sandbox Code Playgroud)
这是在Trip控制器中
def set_s3_direct_post
@s3_direct_post = S3_BUCKET.presigned_post(key: "/uploads/temporary/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read', content_type: 'image/jpeg')
end
Run Code Online (Sandbox Code Playgroud)
这是TripImage模型
class TripImage < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
mount_uploader :photo, PhotoUploader
after_create :process_async
def to_jq_upload
{ …Run Code Online (Sandbox Code Playgroud) 如果我正在写一个私有方法,那么rails会认为这个词下的每个方法private都是私有的吗?或者它应该只对第一种方法是私有的?
private
def signed_in_user
redirect_to signin_url, notice: "Please sign in." unless signed_in?
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
Run Code Online (Sandbox Code Playgroud)
这是否意味着signed_in_user和correct_user私人?还是只是signed_in_user?这是否意味着每当我需要编写私有方法时,它应该在我的文件的末尾?
我在表单中显示一周内的日期列表时遇到问题.
<%= form_for [@hourable, @hour] do |f| %>
<% days = []
Date::DAYNAMES.each_with_index { |x, i| days << [x, i] } %>
<% days.each_with_index do |day,index| %>
<div class="field">
<%= f.check_box day[0] %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我收到了错误
undefined method `Sunday' for #<Hour:0x007fe13c764010>
Run Code Online (Sandbox Code Playgroud)
但是,如果我只是显示
<%= day[0] %>,它会给我一个清单 Sunday, Monday, Tuesday, etc... to Saturday
我在这做错了什么?
谢谢
database ×2
postgresql ×2
ruby ×2
amazon-s3 ×1
carrierwave ×1
dropzone.js ×1
firefox ×1
include ×1
javascript ×1
jquery ×1
keypress ×1
methods ×1
migration ×1
next.js ×1
react-hooks ×1
react-native ×1
react-router ×1
reactjs ×1
router ×1
sql ×1
ssl ×1