ruby-on-rails 相关问题

Ruby on Rails是一个用Ruby编写的开源全栈Web应用程序框架。它遵循流行的MVC框架模型,并以其“面向配置的约定”方法应用程序开发而闻名。

我可以从 Heroku procfile 启动 sidekiq 作业吗?

如果我有一个名为 MigrationWorker 的工作程序,我可以从将代码推送到 Heroku 时运行的 procFile 中运行它吗? 这是我当前启动一切的 procFile,但我想知道我是否可以......

回答 1 投票 0

如何扩展 Ruby Test::Unit 断言以包含assert_false?

显然Test::Unit中没有assert_false。如何通过扩展断言并添加文件 config/initializers/assertions_helper.rb 来添加它? 这是最好的方法吗?我不...

回答 5 投票 0

使用回形针验证大小和内容类型在 Rails 7 中不起作用

我目前正在将在 Rails 3 和 ruby-1.9.3 中构建的旧系统改造为 Rails 7.1.3.2 和 ruby-3.3.0。现在在我的旧应用程序中,它对所有附件使用回形针,所以我也将使用

回答 1 投票 0

Rails 7:上传图像到富文本区域未显示

我在 ruby on Rails 的主页上关注了这个视频:https://rubyonrails.org/。这是我的步骤 Rails 新演示 Rails 生成脚手架帖子标题:字符串内容:文本 Rails 数据库:迁移 导轨服务器

回答 1 投票 0

设置Turbo流broadcasts_refreshes,websocket错误

我正在尝试在本地配置 Rails 7.1.3/Turbo 2.0.5 应用程序,以尝试使用广播刷新作为简单模型。在尝试从该模型进行 Turbo_stream_ 的视图模板上,我得到了 websoc...

回答 1 投票 0

如何通过关系使用has_many批量更新插入标签到rails中的记录?

假设我有一个帖子的经典示例,它通过标签连接表有很多标签。我将如何着手将特定标签一次插入到满足特定条件的多个帖子中。 在

回答 1 投票 0

将 React 视图导出到 MS Word 文档

我正在启动一个项目,我需要执行以下操作: 在网络界面上,用户从数据库中存储的文本元素(调查问题)列表中进行选择。 用户可以重新排列问题的顺序...

回答 1 投票 0

定制刺激反射课程

我正在 Rails 6 中进行一个实验项目。这个项目对我来说的目的是学习新的方法并使用新的(“ish”)技术。 总之,我就是在玩……

回答 1 投票 0

将商品添加到购物车

我需要团队项目的帮助。我的任务是“添加到购物车”功能。我被困住了。我需要在产品页面上的每个项目旁边添加一个按钮,单击该按钮时,它会添加该项目并引导您...

回答 1 投票 0

rails:如何在表单验证后使用 Turbo 刷新列表

我有点按照 Rails 教程来学习它,我想用 Turbo 来学习。 这是我的 index.html.erb 视图: <%= turbo_include_tags %> 注释 我有点按照 Rails 教程来学习它,我想用 Turbo 来学习。 这是我的index.html.erb视图: <%= turbo_include_tags %> <h1>Notes</h1> <turbo-frame id="new_note"> <%= form_with(model: Note.new, url: notes_path) do |form| %> <div> <%= form.label :content %> <%= form.text_area :content %> </div> <%= form.submit "Create Note" %> <% end %> </turbo-frame> <turbo-frame id="notes"> <div> <% @notes.each do |note| %> <div> <p><span><%= note.id %></span><%= note.content %></p> <small> <%= note.created_at %> </small> <%= link_to "Destroy", note_path(note), data: { turbo_method: :delete } %> </div> <% end %> <%= link_to "New note", new_note_path %> </div> </turbo-frame> 我的_list.html.erb模板: <% notes.each do |note| %> <div> <p><span><%= note.id %></span><%= note.content %></p> <small> <%= note.created_at %> </small> <%= link_to "Destroy", note_path(note), data: { turbo_method: :delete } %> </div> <% end %> 这是我的控制器: def index @notes = Note.all.order(created_at: :desc) end ... def new @note = Note.new end def create @note = Note.new(note_params) if @note.save @notes = Note.all # Reload all notes or fetch them as needed respond_to do |format| format.turbo_stream do render turbo_stream: turbo_stream.replace("notes", partial: "notes/list", locals: { notes: @notes }) end format.html { redirect_to notes_url } # Fallback in case JavaScript is disabled end else render :new end end ... 我想在单击提交按钮时创建新注释并更新列表。 我的代码中有两个问题。 第一个是验证后的表单不干净。我不知道最好的方法。 第二个是刷新列表。 它仅在我第一次单击提交按钮后有效一次。如果不刷新页面,我无法创建第二个笔记。另一个问题是新注释添加在列表的末尾而不是开头(因为我的列表是按created_at值排序的)。 你要turbo_stream.update而不是turbo_stream.replace,当你replace时你就失去了<turbo-frame id="notes">,这意味着第二次不起作用: render turbo_stream: turbo_stream.update("notes", partial: "notes/list", locals: { notes: @notes }) <%= turbo_include_tags %> 是一个已弃用的助手,不应使用。 您不必再次重新渲染整个列表。仅将新创建的注释添加到列表中: <!-- app/views/notes/index.html.erb --> <div id="new_note"> <%= render "form", note: Note.new %> </div> <div id="notes"> <%= render @notes %> </div> <!-- app/views/notes/_note.html.erb --> <div id="<%= dom_id note %>"> <%= note.content %> </div> # app/controller/notes_controller.rb def create @note = Note.new(note_params) respond_to do |format| if @note.save format.turbo_stream do render turbo_stream: [ turbo_stream.update(:new_note, partial: "notes/form", locals: {note: Note.new}), turbo_stream.prepend(:notes, @note), ] end format.html { redirect_to notes_url(@note), notice: "Note was successfully created." } else format.turbo_stream do render turbo_stream: [ turbo_stream.update(:new_note, partial: "notes/form", locals: {note: @note}), ] end format.html { render :new, status: :unprocessable_entity } end end end

回答 1 投票 0

Rails 7 Turbo 框架和多种表单的表单值问题

我对 Rails 很陌生。我发现这个奇怪的问题与turbo_frame和多种新形式有关。 我有一个带有评论的模型帖子,当我尝试加载多个表单时,一个表单中的值...

回答 1 投票 0

rails:如何在表单验证后使用 Turbo 刷新列表

我有点按照 Rails 教程来学习它,我想用 Turbo 来学习。 这是我的 index.html.erb 视图: <%= turbo_include_tags %> 注释 我有点按照 Rails 教程来学习它,我想用 Turbo 来学习。 这是我的index.html.erb视图: <%= turbo_include_tags %> <h1>Notes</h1> <turbo-frame id="new_note"> <%= form_with(model: Note.new, url: notes_path) do |form| %> <div> <%= form.label :content %> <%= form.text_area :content %> </div> <%= form.submit "Create Note" %> <% end %> </turbo-frame> <turbo-frame id="notes"> <div> <% @notes.each do |note| %> <div> <p><span><%= note.id %></span><%= note.content %></p> <small> <%= note.created_at %> </small> <%= link_to "Destroy", note_path(note), data: { turbo_method: :delete } %> </div> <% end %> <%= link_to "New note", new_note_path %> </div> </turbo-frame> 我的_list.html.erb模板: <% notes.each do |note| %> <div> <p><span><%= note.id %></span><%= note.content %></p> <small> <%= note.created_at %> </small> <%= link_to "Destroy", note_path(note), data: { turbo_method: :delete } %> </div> <% end %> 这是我的控制器: def index @notes = Note.all.order(created_at: :desc) end ... def new @note = Note.new end def create @note = Note.new(note_params) if @note.save @notes = Note.all # Reload all notes or fetch them as needed respond_to do |format| format.turbo_stream do render turbo_stream: turbo_stream.replace("notes", partial: "notes/list", locals: { notes: @notes }) end format.html { redirect_to notes_url } # Fallback in case JavaScript is disabled end else render :new end end ... 我想在单击提交按钮时创建新注释并更新列表。 我的代码中有两个问题。 第一个是验证后的表单不干净。我不知道最好的方法。 第二个是刷新列表。 它仅在我第一次单击提交按钮后有效一次。如果不刷新页面,我无法创建第二个笔记。另一个问题是新注释添加在列表的末尾而不是开头(因为我的列表是按created_at值排序的)。 你要turbo_stream.update而不是turbo_stream.replace,当你replace时你就失去了<turbo-frame id="notes">,这意味着第二次不起作用: render turbo_stream: turbo_stream.update("notes", partial: "notes/list", locals: { notes: @notes }) <%= turbo_include_tags %> 是一个已弃用的助手,不应使用。 <!-- app/views/notes/index.html.erb --> <div id="new_note"> <%= render "form", note: Note.new %> </div> <div id="notes"> <%= render @notes %> </div> <!-- app/views/notes/_note.html.erb --> <div id="<%= dom_id note %>"> <%= note.content %> </div> # app/controller/notes_controller.rb def create @note = Note.new(note_params) respond_to do |format| if @note.save format.turbo_stream do render turbo_stream: [ turbo_stream.update(:new_note, partial: "notes/form", locals: {note: Note.new}), turbo_stream.prepend(:notes, @note), ] end format.html { redirect_to notes_url(@note), notice: "Note was successfully created." } else format.turbo_stream do render turbo_stream: [ turbo_stream.update(:new_note, partial: "notes/form", locals: {note: @note}), ] end format.html { render :new, status: :unprocessable_entity } end end end

回答 1 投票 0

Rails:bash:./bin/rails:在渲染中部署时权限被拒绝

我开发了一个rails项目并将其推送到github上进行部署。但是我在渲染中部署该项目时遇到以下错误..尽管该项目在本地运行良好.. 对于

回答 1 投票 0

干验证。如何将参数发送到宏

json(简单示例): { “人”: { “生日”:“1990年10月10日” }, “成就”:{ “date_appr_r”:“2022-05-21” } } 我的骗局...

回答 1 投票 0

tailwind.css 未在 Heroku 的 Rails 7 项目中生成

我有一个使用 TailwindCSS 部署到 Heroku 的 Rails 7 项目,该项目在 rake asset:precompile 期间没有构建 tailwind.css,我不知道为什么。当我尝试访问该应用程序时,它崩溃了...

回答 4 投票 0

nil:NilClass 的未定义方法 `each'...为什么?

rails 指南示例,单击按钮保存帖子,控制台显示此消息: 于 2013-12-25 22:42:04 +0800 开始为 127001 发布“/posts” 由 PostsController#create 作为 HTML 参数处理...

回答 4 投票 0

GitHub Actions CI - Gem/Rails Engine - Ruby v3.3.1/Bundler 错误

我正在编写一个 Ruby gem/Rails 引擎 blacklight_allmaps,并使用 GitHub Actions 进行 CI。昨天,我的 Ruby v3.2 测试构建顺利通过,但我的 Ruby v3.3 测试开始失败,并出现一个奇怪的错误......

回答 1 投票 0

隐藏部分电子邮件地址

使用 ruby 例如隐藏电子邮件地址@符号之前的 4 个字符的最佳方法是什么 [email protected] = fake####@example.com 当我显示

回答 4 投票 0

`update` 上的 `after_commit` 回调不会触发

我已经定义了更新时的 after_commit 回调。它不会在 rspec 中触发。 这是我的回调: after_commit :notify_trip, :if => Proc.new { |trip| trip.can_send_schedule_notification? },哦...

回答 3 投票 0

仅在创建时使用 after_commit

我有一个带有 after_commit 的 UserObserver (从 after_create 更改以避免出现 id 未找到的竞争条件错误)来更新计数。但我知道每次创建、更新都会执行

回答 3 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.