Tag: ruby on rails 4

如果页面在ROR上更改,则创建条件以隐藏渲染

我使用camaleon CMS在rails上有默认模板,如下所示: 如果页面从默认值更改(ex = localhost:3000),我想创建条件,然后所有部分渲染将被隐藏(不显示在其他页面上,ex = localhost:3000 / about将不显示所有部分渲染)。 由于我正在使用CMS并自动生成页面并且将显示在yield部分,因此很难创建另一个视图文件。 任何人都可以帮我解决这个问题吗? 谢谢!

用户中的NoMethodError#unsubscribe

我正在努力实现我的rails邮件的取消订阅链接。 不幸的是,我的代码打破了这个: 用户中的NoMethodError#unsubscribe – nil的未定义方法`unsubscribe_hash’:NilClass 它指向/app/views/users/unsubscribe.html.erb第3行 Unsubscribe from Mysite Emails By unsubscribing, you will no longer receive email… 我的user_controller如下所示 class UsersController < ApplicationController protect_from_forgery def new @user = User.new end def create @user = User.new(secure_params) if @user.save flash[:notice] = "Thanks! You have subscribed #{@user.email} for Jobs Alert." else flash[:notice] = 'Error Subscribing! Kindly check your […]

未允许的参数:profile(NestedAttributes) – RAILS 4

这个问题多次被其他用户询问,但仍未解决我的问题。 我的rails应用程序出现问题,出现错误“未允许的参数:配置文件”。 user_controller.rb class Admin::UsersController (1)” if @user.update(user_params) redirect_to edit_admin_user_path, notice: “#{@user.profile.full_name} account has been updated.” else render ‘edit’ end end private def set_user @user = User.find(params[:id]) end def user_params params.require(:user).permit(:id, :username, :email, profile_attributes: [:user_id, :full_name]) end end edit.html.erb “form-control” %> “form-control” %> “btn btn-primary” %> User.rb class User { :case_sensitive => false } end […]

Rails4:如何设置最大值+ 1

提供以下型号: class Schedule < ActiveRecord::Base has_many :rooms accepts_nested_attributes_for :rooms, allow_destroy: true end class Room < ActiveRecord::Base belongs_to :schedule end 我想要做的是为添加的数据设置最大值+ 1。 例如,在更新之前 Day 1 schedule_title A room_name A 更新后, Day 1 schedule_title A room_name A Day 2 # I’d like to set `2` to `day` column in room table schedule_title B room_name B 当我添加下一个房间时,我想为房间表中的新数据设置2到day列。 schema.rb […]

通过轨道5传递隐藏的字段标记参数

在views/plans/new.html.erb我得到了plan_id和price params,其中包含以下内容: plan.id, :price => plan.price) %> 然后该应用程序重定向到注册页面,并使用以下内容保留以前的参数并添加电子邮件: registrations_controller.rb def after_sign_up_path_for(resource) new_transaction_path(session[:registration_params].merge(ema‌​il: resource.email)) end def after_inactive_sign_up_path_for(resource) new_transaction_path(session[:registration_params].merge(ema‌​il: resource.email)) end 最后,在注册后,应用程序会重定向到views / transcation / new.html.erb,其中包含plan_id , price和email参数。 Parameters: {“ema‌​il”=>”example@gmail.com”, “plan_id”=>”bs96”, “price”=>”150.0”} 此时我正在尝试将电子邮件参数传递给 但是没有收到电子邮件,如下所示: Parameters: {“utf8″=>”✓”, “authenticity_token”=>”KeS2xK7NIJZwFQvW2kJKupcpURnQweq+yoRgk9AJ1aaOgFIIym4RKadI4jc6vYynMo4vKR4eLmdIynfBG+EusQ==”, “email”=>””, “plan_id”=>”bs96”, “amount”=>”150.0”, “payment_method_nonce”=>”0c22f2fa-e212-0ad3-753b-0d183d02522b”} 关于我做错什么的任何想法??? UPDATE1 在views / transcation / new.html.erb中,ui中有braintree drop,脚本连同三个隐藏字段: braintree.setup(“”, ‘dropin’, { container: ‘dropin’ });

rake退出状态:139

我关注https://gorails.com/deploy/ubuntu/16.04 我正在运行:“捆绑exec cap生产部署”并收到以下错误: 01 $HOME/.rbenv/bin/rbenv exec bundle install –path /home/deploy/deploy_test1/shared/bundle –without development test –deployment –q… ✔ 01 deploy@107.170.84.18 3.251s 00:21 deploy:assets:precompile 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile 01 /home/deploy/deploy_test1/shared/bundle/ruby/2.4.0/gems/activesupport-4.2.4/lib/active_support/core_ext/numeric/conversions.rb:121: w… 01 /home/deploy/deploy_test1/shared/bundle/ruby/2.4.0/gems/activesupport-4.2.4/lib/active_support/core_ext/numeric/conversions.rb:121: w… 01 bash: line 1: 23934 Segmentation fault (core dumped) $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile (Backtrace restricted to imported tasks) cap […]

Ruby on Rails命名为model的class属性

我有两个类Product和user ,它们具有与多态类型的has_many关系。 class User < ActiveRecord::Base has_many :pictures, as: :imageable end class Product < ActiveRecord::Base has_many :pictures, as: :imageable end class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true end 我还想为profile_picture的用户模型添加一个新属性,因此@user.profile_picture将返回一个图片对象。 怎么能实现呢? 特别是向用户添加外键的迁移。 编辑:我已经更新了用户模型 has_one :profile_picture, class_name: “Picture”, foreign_key: “profile_picture_id” 并添加了以下迁移 add_column :users, :profile_picture_id, :integer 然而我似乎无法设置个人资料图片,如果有人可以解释我做错了什么,将不胜感激。 谢谢!

允许类别中的多个记录提交到列表

如果选择了多个列表,我希望将多个(数组……)category_id保存到每个列表中。 以下是所有内容的设置方式,包括类别如何与列表一起使用。 分类型号: class Category < ApplicationRecord validates_uniqueness_of :category has_many :listings 上市模型: has_and_belongs_to_many :categories, required: false attr_accessor :new_category_name before_save :create_category_from_name # has_many :categories 计划(类别和列表): create_table “categories”, force: :cascade do |t| t.string “name” t.datetime “created_at”, null: false t.datetime “updated_at”, null: false end create_table “listings”, force: :cascade do |t| t.string “name” t.text “description” t.decimal “price” t.datetime “created_at”, […]

按输入表格编辑相关模型?

Order has_many jobs Job belongs to order 我想编辑@job.order属性: (…) 通过简单的forms使用输入的任何方式吗?

如何创建搜索function – Ruby On Rails

我试图为应用程序创建搜索function。 我有一个名为搜索的服务对象,所有搜索逻辑都在此对象中。 当搜索表单与about查询一起提交时,Search Controller中的@results是以下数组。 => [ [0] [], [1] [ [0] About { :id => 2, :title => “About”, :slug => “about”, :meta_description => “”, :meta_keywords => “”, :content => “Lorem ipsum about”, :position => 1, :published => true, :on_menu => true, :created_at => Wed, 13 Jan 2016 00:44:08 UTC +00:00, :updated_at => Fri, 15 […]