Tag: ruby on rails 5

skip_before_filter用于设计的“登录”操作

我可以这样做,在我需要的某个控制器中跳过调用“authenticate_user”: class ApplicationController before_filter :authenticate_user! end class MyController < ApplicationController skip_before_filter :authenticate_user! end 我想调用skip_before_filter来设计skip_before_filter的“login”操作,我不想重写任何其他内容。 我怎样才能做到这一点?

Rails – 从单独的设置控制器编辑用户和配置文件模型

我正在努力弄清楚如何让它工作,但基本上我有2个模型: class User class Profile 一个用户有一个配置文件。 我还有一个带有“配置文件”和“更新”操作的SettingsController: class SettingsController < ApplicationController def profile @profile = User.find_by_id(current_user).profile end def update set_profile respond_to do |format| if @profile.update(profile_params) format.html { redirect_to @profile, notice: 'Profile was successfully updated.' } else format.html { render :edit } end end end private def profile_params params.require(:profile).permit(:name) end end 和/ settings / profile页面: Settings […]

Rails 5白名单css属性为sanitize帮助

我需要允许内联”style=position: absolute;” 由sanitize(post.content)输出sanitize(post.content) 。 我找到了Rails 4的文档说 config.action_view.sanitized_allowed_css_properties = [‘position’] 在application.rb中会添加属性到白名单,但是我找不到文档是否仍然是Rails 5的情况,并且它在多次重启服务器后似乎没有工作。 有没有办法轻松添加白名单css属性? 这个Rails 4的答案暗示了一个猴子补丁,但我不知道在哪里或如何这样做。 更新:安装gem rails-deprecated_sanitized允许上面的配置行工作,因此看起来不推荐使用sanitized_allowed_css_properties。 当然有一种方法可以在Rails 5中做到这一点? 我不能回到4,我需要将内联样式位置列入白名单,以便让第三方插件工作(CKEditor + Iframely)

Rails:将`master.key`移动到生产服务器

我正在尝试使用mina将更新版本的rails应用程序部署到DigitalOcean上的Droplet 当我运行mina deploy我得到错误Missing encryption key to decrypt file with. Ask your team for your master key and write it to /home/my_rails_project/app/tmp/build-153920174210305/config/master.key or put it in the ENV[‘RAILS_MASTER_KEY’] Missing encryption key to decrypt file with. Ask your team for your master key and write it to /home/my_rails_project/app/tmp/build-153920174210305/config/master.key or put it in the ENV[‘RAILS_MASTER_KEY’] 。 我期待这个错误,因为我还没有弄清楚如何将细节添加到服务器。 一些文章表明有两种方法可以做到这一点 […]

在构建全局自动完成搜索时,如何在搜索栏中修复未定义的方法`form_with’?

尝试在我的rails应用程序中跨多个模型运行全局自动完成搜索并利用easy-autocomplete jquery库以及用于搜索的ransack gem时,我收到一个奇怪的错误。 具体来说,我相信错误发生在我的导航栏页面中,当我尝试undefined method form_with for #<#:0x007f87600e0aa8>运行查询undefined method form_with for #<#:0x007f87600e0aa8>时出现此错误undefined method form_with for #<#:0x007f87600e0aa8> 我决定破解并切换form_tag的form_with然后我在undefined method text_field for nil:NilClass”下面的行上得到一个错误undefined method text_field for nil:NilClass”我已经在下面列出了我所有的相关代码。非常感谢你的任何帮助。 Main_Controller.rb class MainController < ApplicationController def index end def search @movies = Movie.ransack(name_cont: params[:q]).result(distinct: true) @directors = Director.ransack(name_cont: params[:q]).result(distinct: true) respond_to do |format| format.html {} format.json { @movies = @movies.limit(5) […]

`在块中抢救(2级)需要’:尝试加载gem’sass-rails’时出错。 (捆扎机:: GemRequireError)

我完成了在我的ubuntu系统(16.04.2 LTS)上安装rails 5,当我尝试运行rails server命令时,我遇到了这个错误。 `rescue in block (2 levels) in require’: There was an error while trying to load the gem ‘sass-rails’. (Bundler::GemRequireError) gem加载错误是:未初始化的常量Sass :: Script你的意思是? ScriptError 当我写捆绑更新时,提示显示此消息: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only […]

Link_to root_path在邮件视图中不起作用

我正在尝试将基本的link_to标记添加到邮件视图中。 notification.html.erb: 错误是undefined local variable or method ‘root_path’不太确定为什么相同的代码位(仅限不同的图像)在普通的控制器视图中完美地工作。 root_path在路由中正确设置。 邮件视图会阻止它吗?

在完成重新加载之前,Rails 5重新加载器转移到下一个中​​间件

在rails 5开发模式中,在代码更改和刷新之后,它会触发重新加载器中间件来卸载/重新加载类。 但在重新加载重新加载之前,请求将移至下一个中间件。 重新加载器包含执行程序并查看executor.rb 。 似乎下一个中间件在run!后被调用run! 在complete!之前complete! 这与以下日志消息一致。 我想知道我是否可以确保下一个中间件仅在重新加载后调用。 我试图用Rails.application.executor.wrap , Rails.application.reloader.wrap和ActiveSupport::Dependencies.interlock.permit_concurrent_loads包装cusstomMiddle调用,但结果不是那些工作。 Rails版本:5.1 Ruby版本:2.4.1 我添加了以下日志消息,请参阅事件序列。 application.rb中 ActiveSupport::Reloader.before_class_unload do puts “Before class unload, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.after_class_unload do puts “After class unload, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.to_run do puts “Reloading, Thread Id: #{Thread.current.object_id}” end ActiveSupport::Reloader.to_complete do puts “DONE Reloading, Thread Id: #{Thread.current.object_id}” end custom_middleware.rb def […]

Turbolinks缓存之前和之后的Javascript DOM事件

我在这里: $(document).on ‘turbolinks:load’, -> console.log “page has loaded!” $ -> $(“button#show-hide”).click (e) -> e.preventDefault() 这使得我的click事件仅在Turbolinks缓存页面后可用。 我可以做$(document).on ‘turbolinks:before-visit ,只有在Turbolinks缓存之前才能使事件可用。 我应该如何随时提供活动?

如何将关联加载到实例变量?

在模型中我有: class CalendarItem < Resource belongs_to :schedule has_many :people has_many :documents acts_as_list scope: :schedule, column: :visual_position validates :schedule, :title, presence: true end 然后在控制器中: class ScheduleController < ApplicationController def show @calendar_items = CalendarItem.where(schedule: @schedule).includes(:people, :documents) end … end 在视图中,我正在使用react-rails渲染react_component(但这应该有所不同): = react_component(‘CalendarItemsList’, calendar_items: @calendar_items) 但是它不会将关联数据传递给视图(react_component),只传递主模型。 我以前经历过这种情况,没有反应前端,也没有用。 可能有什么不对?