Tag: ruby on rails 4

PG :: UndefinedTable:错误:关系“carrinho”不存在

我正在使用rails 4,ruby 2.3并且有问题。 怎么解决这个错误? PG :: UndefinedTable:错误:关系“carrinho”不存在第1行:选择“carrinho”。* FROM“carrinho”WHERE“carrinho”。“id”I … ^:SELECT“carrinho”。* FROM“carrinho “WHERE”carrinho“。”id“IS NULL LIMIT 1 我的模型是carrinho.rb我的控制器是carrinhos_controller.rb我的观点是carrinhos我的迁移是20160204181641_create_carrinhos.rb 在变形中有: inflect.plural “carrinhos”, “carrinhos” inflect.plural “carrinho”, “carrinhos” inflect.singular “carrinhos”, “carrinho” inflect.singular “carrinho”, “carrinho” inflect.irregular ‘carrinho’, ‘carrinhos’ 让我试着解决这个问题的一周。 请帮我!!

ActionController :: ParameterMissing(param丢失或值为空:film):

所以,当我试图访问我的应用程序上的电影页面时,我收到以下错误: ActionController::ParameterMissing (param is missing or the value is empty: film): 2014-07-24T22:04:44.622356+00:00 app[web.1]: app/controllers/saas_admin/films_controller.rb:54:in `permitted_params’ 请参阅下面的电影控制器代码 films_controller.rb class SaasAdmin::FilmsController :find_by_id!, :param => :studio_id, :class_name => Studio before_filter :set_sort_fields, :only => :edit before_filter :build_collections, :only => [:new, :create, :edit, :update] def create create! { parent_path(parent.id) } # Redirect to studio in case studio_id is changed end […]

如何在rails 4中转换用户输入?

我正在创建一个应用程序,用户可以在其中输入将作为化学符号返回的名称(匹配时)。 所以我设法在控制台中做了: symbols = { “ac” => “Ac”, “al” => “Al”, “am” => “Al”, “br” => “Br”, “ba” => “Ba”, “cr” => “Cr” } puts “Get your chemical name!” name = gets.chomp name.gsub!(/#{symbols.keys.join(‘|’)}/, symbols) puts name 现在我想让它在应用程序中工作,但我不知道如何创建该方法? 我希望它只在views / show中显示 = @convertor.name = link_to ‘Edit’, edit_convertor_path(@convertor) = link_to ‘Back’, convertors_path 我应该在我的模型中创建方法还是在哪里? class Convertor “Ac”, “al” […]

如何通过检查URI是否引用给定的域名来validationURI?

我正在运行Ruby on Rails 4.1.1,我想通过检查URI是否在给定的域名内来validationURI。 也就是说, uri字符串可以作为params发送到我的控制器,我想检查uri “引用”我的应用程序域名www.myapp.com 。 当然, uri应该是有效的URI引用 。 # Invalid URIs www.website.com http://www.website.com http://www.website.com/ https://www.website.com/ ftp://www.website.com/ ftps://www.website.com/ http://www.website.com/some/path # Valid URIs www.myapp.com http://www.myapp.com http://www.myapp.com/ https://www.myapp.com/ ftp://www.myapp.com/ ftps://www.myapp.com/ http://www.myapp.com/some/path 我怎样才能做到这一点(也许只使用Ruby on Rails)? 注意:我正在validationURI,以便允许用户设置自定义重定向,并且我知道漏洞 。 我计划在application_controller.rb声明的方法中运行validation。

Schema.rb显示由于以下NoMethodError#undefined方法`’为nil:NilClass,因此无法转储表“progress”

我正在尝试使用Carrierwave添加一个多图像上传器, 然后 将文档添加到我的应用程序中。 通常我的schema.rb看起来像这样 ActiveRecord::Schema.define(version: 20160814232416) do create_table “progresses”, force: :cascade do |t| t.string “title” t.string “date” t.text “content” t.datetime “created_at”, null: false t.datetime “updated_at”, null: false end end 当我跑: rails g migration add_images_to_progresses images:json和rake db:migrate 我的架构改变并显示出奇怪的东西……是Sqlite3还是Pg的问题? 我该怎么办 ? ActiveRecord::Schema.define(version: 20160815005123) do # Could not dump table “progresses” because of following NoMethodError #undefined method `[]’ […]

加载父资源失败的私有方法

从上一个: Rails 4嵌套资源/路由……差不多……? 我的行控制器中的私有方法将制造商加载到控制器中会引发错误… 我使用before_filter:load_manufacturer function是: def load_manufacturer @manufacturer = Manufacturer.find(params[:manufacturer_id]) end 当我尝试编辑表单中的行实例时,我得到: Couldn’t find Manufacturer with id=1 但我正在尝试编辑父资源(37)的子资源(1)… http://localhost:3000/manufacturers/37/lines/1 这里传递的参数是: {“manufacturer_id”=>”manufacturer_id”,”id”=>”1″} 而我的forms,使这些模型很好,是: 应用程序/视图/线/ _form.html.erb prohibited this line from being saved:

Rails确定has_many:通过访问额外数据

我们知道,在rails中你可以为你的has_many :through添加额外的属性has_many :through连接模型 我想从连接模型中提取额外的数据并用它填充视图。 我通过直接引用连接模型来实现这一点,但是我想将相关的连接模型数据附加到当前项目,如下所示: #app/models/message.rb #Images has_many :image_messages, :class_name => ‘ImageMessage’ has_many :images, :class_name => ‘Image’, :through => :image_messages, dependent: :destroy #app/views/messages/show.html.erb #-> works #app/views/messages/show.html.erb #-> what I’d like to happen 具体来说,我需要能够调用特定图像的caption , caption存储在image_messages连接模型中,如下所示: #image_messages join table id | message_id | image_id | caption | created_at | updated_at 从我所看到的,也许可以使用范围,但我不确定 任何帮助将不胜感激! 我想我会问这个问题,因为这是你不经常得到的那个问题之一!

订阅条纹

我已经阅读了这篇https://stripe.com/docs/tutorials/subscriptions,但并不真正理解有关实现的订阅的想法。 我需要的是给用户充电,但是我自己计算充电量,因为我有一个特殊的算法。 所以这段代码: # create a plan – once! Stripe::Plan.create( :amount => 2000, :interval => ‘month’, :name => ‘Amazing Gold Plan’, :currency => ‘cad’, :id => ‘gold’ ) # every month? or also once? maybe_customer = Stripe::Customer.retrieve(….) unless maybe_customer customer = Stripe::Customer.create( :card => token, :plan => “gold”, :email => “payinguser@example.com” ) end 什么时候(多久一次)我必须运行它:只有一次或每个月( :interval […]

Rails 4:嵌套表单上的重复file_field输入

我有一个模型“post”和一个模型“照片”。 模型post具有来自照片的嵌套表单以上传具有关联的图像。 上传工作正常,但每次我去编辑post时,我都会为每个上传的图片添加新的输入,并且还有一个输入来上传新图像。 我想只输入上传新文件并隐藏或不加载其他文件。 这是我的代码: 控制器: module Admin class SeminovosController true, ‘max-stale’ => 0 end # GET /seminovos/1 # GET /seminovos/1.json def show end # GET /seminovos/new def new @seminovo = Seminovo.new @seminovo.photos.build @seminovo.photos end # GET /seminovos/1/edit def edit @seminovo.photos.build @seminovo.photos end # POST /seminovos # POST /seminovos.json def create #@seminovo = Seminovo.new(seminovo_params) respond_to […]

无法在Heroku上部署Ruby on Rails应用程序?

我已经在Heroku上成功部署了Ruby on Rails应用程序。 但是,当我访问Heroku提供的URL时,错误说:“您要查找的页面不存在。” url – https://cryptic-waters-2558.herokuapp.com/ 请帮忙。