Tag: ruby on rails 4

使用路易gem的电子邮件中的图像

我想知道如何使用roadie gem在电子邮件中显示图像。 使用roadie我可以内联我的样式表,但它没有显示图像。 我试过了两个 和 or 在我的邮件模板中,但它没有显示任何图像。 有帮助吗?

邪恶的gem与茧gem和设计用户模型

所以我有一个User devise生成的User模型,我正在使用Wicked gem为我提供多forms选项,从用户那里获取更多数据并将其存储在用户模型中。 一切都工作正常,但知道我正在尝试添加另一个用户有很多学位的模型。 我正在使用cocoon gem让我增加额外的degrees 。 我可以进入多forms页面并输入学位信息,甚至可以向用户添加更多学位,但是当我提交表单时,我收到错误; param is missing or the value is empty: user 其他所有其他内容实际上都得到了保存,我可以查看用户和输入的其余字段但不是度数。 用户模型: has_many :degrees accepts_nested_attributes_for :degrees, reject_if: :all_blank, allow_destroy: true 学位模型: belongs_to :user user_steps_controller(这是邪恶的gem控制器): class UserStepsController < ApplicationController include Wicked::Wizard steps :personal, :avatar_and_about_yourself, :social, :education def show @user = current_user render_wizard end def update @user = current_user @user.update_attributes(user_params) […]

Rails和RSpec:在不同的命名空间(模块)中测试具有相同名称的控制器

我有使用RSpec 3.4.0测试的rails 4.1.16 API应用程序,我遇到了在不同模块中测试名为同名的类的问题。 结构是: app/controllers/bar/notifications_controller.rb class Bar::NotificationsController < ApiController … end 和控制器在不同的模块中具有相同的名称: app/controllers/foo/bar/notifications_controller.rb module Foo class Bar::NotificationsController < ApiController … end end Foo是一个新模块,还没有测试。 添加之后,旧的Bar::NotificationsController所有相应控制器测试都开始失败。 规范文件: spec/controllers/bar/notifications_controller_spec.rb require ‘spec_helper’ describe Bar::NotificationsController, type: :controller do … end 该规范文件中的所有测试都失败并出现相同的错误: RuntimeError: @controller is nil: make sure you set it in your test’s setup method. 当我更改Foo模块中的控制器名称时,问题不存在: app/controllers/foo/bar/foo_notifications_controller.rb module Foo […]

Rails4和Devise(NoMethod错误)

我正在学习如何使用rails gem在ruby上构建Web应用程序。 遵循本教程: http : //12devs.co.uk/articles/writing-a-web-application-with-ruby-on-rails/ 在我开始为用户身份validationfunction安装Devise gem之前,一切都很好。 在执行rails generate devise:install之后我收到错误 错误报告是这个史诗(看起来我以某种方式搞砸了一些依赖): sergey@sergey-VirtualBox:~/Bookmarks$ rails generate devise:install /home/sergey/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.0/lib/active_record/dynamic_matchers.rb:26:in `method_missing’: undefined method `devise’ for Install (call ‘Install.connection’ to establish a connection):Class (NoMethodError) from /home/sergey/Bookmarks/app/models/install.rb:4:in `’ from /home/sergey/Bookmarks/app/models/install.rb:1:in `’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `load’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `block in load_file’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:633:in `new_constants_in’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:442:in `load_file’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:342:in `require_or_load’ from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:480:in […]

创建我的用户时,参数数量错误(0表示1)

我知道有很多问题,但我无法找到答案。 所以,我构建了一个Rails 4 API,我尝试创建一个发布JSON请求的用户。 这里有一些我的代码: user.rb: class User “Position”, foreign_key: “position_current_id” has_many :positions searchkick locations: [“location”] def search_data attributes.merge location: [current_position.latitude, current_position.longitude] end devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable end application_controller.rb class ApplicationController < ActionController::Base respond_to :json, :html protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format =~ %r{application/json} } end registrations_controller.rb class Api::RegistrationsController {:token […]

渲染部分视图时ajax中的动态内容

当用户点击不同的链接时,如何获得动态内容? 视图/仪表板/ index.html.haml .container – @trips.each do |trip| = link_to trip.id, quick_view_trips_path, remote: true 我很确定quick_view_trips_path是不正确的,因为所有链接都是这样的: 1 13 51 不知何故,我需要使这些链接动态化,然后当用户点击它时,模态窗口也将是动态的。 如果我用quick_view_trips_path替换quick_view_trips_path = link_to trip.id, trip, remote: true 没有任何反应,并且url会更改为正确的url,但我的模态窗口不会通过ajax呈现。 以下是url现在的样子: 1 除了我想用动态内容完成的事情,有没有办法可以改变我的url: 1 是否可以获取?quick_view=on附加到URL的末尾并使一切工作再次起作用? 以下是我的其余代码: 意见/车次/ quick_view.js.erb $(‘body’).append(”); 意见/车次/ _quick_view.html.haml .root-container = @trip.title = @trip.image = @trip.more_details 这现在无法正常工作,因为我的应用程序返回undefined method 的routes.rb resources :trips do collection do get ‘quick_view’ […]

使用连接表元数据创建Rails 4表单

非常新的Rails 4开发人员。 我有一个用户正在创建练习的表单。 练习可以有很多设备,而设备可以是可选的(想想俯卧撑是做俯卧撑)。 我将此“可选”字段存储在连接表exercise_equipment中。 我无法获取参数来实际发送我选择的集合元素的值。 请参阅下面的模型,视图,控制器和参数。 以下是我的模型的属性/关系: # id :integer # name :string # is_public :boolean Exercise has_many :exercise_equipment has_many :equipment, :through => :exercise_equipment accepts_nested_attributes_for :exercise_equipment # id :integer # exercise_id :integer # equipment_id :integer # optional :boolean ExerciseEquipment belongs_to :exercise belongs_to :equipment accepts_nested_attributes_for :equipment # id :integer # name :string Equipment has_many :exercise_equipment […]

ruby on rails 4 – devise – send_reset_password_instructions – 重置密码 – 重置密码令牌无效

我在rails版本’4.2.4’上使用ruby并设计4.0.0 gem ‘rails’, ‘4.2.4’ devise (4.0.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, 1.2.3) 接管一些由某人制作的代码,他们已经实现了重置密码,但没有完成工作。 我想解决它。 从控制台,我试图使用这个: > u = User.first > u.send_reset_password_instructions 这是控制台输出: [15] pry(main)> u.send_reset_password_instructions Devise::Mailer#reset_password_instructions: processed outbound mail in 37.9ms Sent mail to testme@gmail.com (6024.6ms) Date: Sun, 20 May 2018 12:13:23 +0800 From: “My Support” Reply-To: “Harta.Org Support” To: testme@gmail.com […]

如何不仅获得单个记录,还获取属于特定搜索查询的所有记录

我写了这个搜索查询,只返回一条记录: @messages = Message.find_by_sender_username(@user.username) # 虽然在我的消息模型中我有两条记录,其中包含sender_username“emmanuel” # # 我认为问题在于模型之间没有真正的关系: 管理员用户名:string 用户名:string 信息 SENDER_USERNAME:字符串 reciepent_username:字符串 身体:字符串 阅读:布尔 MyQuestion是我应该如何写这些模型之间的关系,我为这种关系注意了关于forgein_key的一些事情,但我不是100%肯定如何利用它!

在Rails中的控制器和视图中使用的辅助方法

我知道我可以在Rails中的helper文件夹中的Helper类中放置一个帮助器方法。 然后该方法可以在任何视图中使用。 我知道我可以在ApplicationController类中放置方法,并且该方法可以在任何控制器中使用。 放置控制器和视图中经常使用的方法的适当位置在哪里?