Tag: 的Ruby on 轨道

Rails:“状态”没有正确插入params?

嗨我目前收到表单提交错误。 我的应用程序基本上是一个用户,相册,图片(图片上传)。 但是,当我尝试创建新专辑时,它给了我错误: AlbumsController#show中的ActiveRecord :: RecordNotFound 找不到ID = 123的专辑[WHERE“album_users”。“user_id”= 29 AND(status =’accepted’)] 问题是每张专辑可以有多个所有者,因此在创建专辑的表单中有一个复选框部分,您可以在其中突出显示您的朋友姓名并“邀请他们”成为所有者。 这就是我的创建函数看起来有点奇怪的原因。 这里的问题是让:status =>’accepted’正常插入。 请帮忙! 专辑控制器 def create @user = User.find(params[:user_id]) @album = @user.albums.build(params[:album], :status => ‘accepted’) @friends = @user.friends.find(params[:album][:user_ids]) for friend in @friends params[:album1] = {:user_id => friend.id, :album_id => @album.id, :status => ‘pending’} AlbumUser.create(params[:album1]) end #the next line is where the […]

Ruby On Rails:使用创建控制器函数中新控制器函数的参数

我传入:number作为参数,然后将其分配给before_filter控制器中的变量@test_suite_num。 在我在控制器中的new函数中,我使用变量@test_suite_num来过滤名为Test的表,以获取id为@test_suite_num的条目的计数。 我使用此计数生成适当数量的子资源test_run 。 我为create做同样的事情,但由于某些原因,每当我在依赖@test_suite_num的表单中使用这些变量时,我都会收到nil错误。 我假设因为create从不接受参数,所以变量永远不会被初始化。 如何在create函数中使用@test_suite_num? 控制器代码: before_filter :get_number, :only => [:new, :create] def get_number @test_suite_num = params[:number] end 新 def new @test_suite_run = TestSuiteRun.new @tests = Test.find(:all, :conditions => { :test_suite_id => @test_suite_num }) @tests.count.times do test_run = @test_suite_run.test_runs.build end end 创建 def create @test_suite_run = TestSuiteRun.new(params[:test_suite_run]) @tests = Test.find(:all, :conditions => { […]

在Facebook上使用Oauth之后,如何获取用户创建的页面图表?

在OAuth与facebook之后,如何获取用户创建的页面图表? 我搜索了在OAuth之后facebook发送给我的回调中的文档和事件搜索,我仍然无法获取用户创建的页面,我必须使用FQL吗? 我如何在rails中使用FQL?

如何在rails中创建锚点?

如何将以下内容翻译为link_to标记? Click here to see my portfolio. ….

收集选择has_many通过

当表单重新显示时,如何获取集合选择以显示所选的已提交值? 例如,如果其他字段未validation,则多选框应显示所选项目 true, :class => ‘chosens-select’, :name=>’coupon[activity_ids][]’}) %>

Rails 3.1限制子模型的数量

大家好我有两个模型:用户(又名父母)和Profil(又名儿童)。我想将用户的个人资料数量限制为一个。 车型/ user.rb class User < ActiveRecord::Base has_one :profil end 车型/ profil.rb class Profil :create def limit_profil_to_one if self.user.profils(:reload).count > 1 errors.add(:base, “Exceeded thing limit”) end end end 但是当我尝试创建一个profil时,我收到以下错误消息: NoMethodError (undefined method `profils’ for nil:NilClass): app/models/profil.rb:11:in `limit_profil_to_one’ app/controllers/profils_controller.rb:52:in `block in create’ app/controllers/profils_controller.rb:51:in `create 控制器/ profils_controller.rb # -*- encoding : utf-8 -*- class ProfilsController < ApplicationController […]

ElasticSearch with Tire不包括带STI模型的自定义分析器

我有一个STI模型,我希望可以使用ElasticSearch和Tire进行搜索。 我遇到的问题是当Tire创建映射时,似乎忽略了我的第二个模型的自定义分析器。 以下是我的模型示例。 class Account { :analyzer => { “custom_search_analyzer” => { “tokenizer” => “keyword”, “filter” => “lowercase” }, “custom_index_analyzer” => { “tokenizer” => “keyword”, “filter” => [“lowercase”,”substring”] } }, :filter => { :substring => { “type” => “nGram”, “min_gram” => 1, “max_gram” => 20 } } } do mapping do indexes :id, :type => […]

循环工作,但邮件不

我有一种方法,基本上会发出通知,告知有人在我的应用中提交了表单。 我最近更改了我的模型,以便通过添加user_designations模型来处理所有分配(用户被分配到哪个学校等)来通知多个人。 方法: def new_message(applicant) @applicant = applicant @applicant.school.users.each do |user| mail(:to => user.email, :subject => “Submitted Application”) end end 对象: class Applicant belongs_to :school class School has_many :applicants has_many :user_designations has_many :users, :through => :user_designations class User has_many :schools, :through => :user_designations has_many :applicants, :through => :schools 邮件function仅适用于循环的最后一次迭代。 我也收到一个错误: #School的未定义方法`user’:0x007fe064700890 基于这些少量信息的任何想法?

如何为Ruby on Rails应用程序启用Trace

是否有能力在Ruby on Rails控制器类中的方法中启用某种类型的系统跟踪? 找到执行源代码的真正困难。

在嵌套事务中,如果外部事务被回滚,内部事务是否会回滚?

model1.rb def method1 Model1.transaction do model2_ref_obj = Model2.find(some_id) model2_ref_obj.method1 end end model2.rb def method1 Model2.transaction do ## so some work self.save! end end 当model1的事务回滚时,内部事务是否也会回滚?