Tag: ruby on rails 4

Rails指南第5.12节中的UrlGenerationError

我正在按照Rails 4.0.0的入门教程进行操作: http : //guides.rubyonrails.org/getting_started.html#updating-posts 当我尝试从主页面(localhost)导航到localhost / posts时,我收到此错误: ActionController::UrlGenerationError in Posts#index Showing C:/RailsInstaller/blog/app/views/posts/index.html.erb where line #16 raised: No route matches {:action=>”show”, :controller=>”posts”} missing required keys: [:id] Extracted source (around line #16): 13 14 15 16 17 18 19 此外,当我尝试编辑post时,我在edit.html.erb文件中收到一个SyntaxError: C:/RailsInstaller/blog/app/views/posts/edit.html.erb:3: syntax error, unexpected ‘}’, expecting keyword_end ‘;@output_buffer.append= form_for :post, url: post_path(@post.id) }, ^ C:/RailsInstaller/blog/app/views/posts/edit.html.erb:32: syntax […]

Ruby on Rails-Action邮件没有按照要求?

我有2个模型po和send po:has_many发送 发送:belongs_to po send po send_controller class SendsController < ApplicationController def new @send = Send.new end def create @send = Send.new(params[:send]) if @send.save Pomailer.registration_confirmation(@send).deliver flash[:success] = "Send mail" redirect_to capax_path else flash[:warning] = "mail not send" redirect_to capax_path end end pomailer class Pomailer “xyz@yahoo.co.in”, :subject => ” New purchase order send by ” ) […]

在网站中嵌入PDF,允许用户修改PDF中的可编辑字段,然后保存回服务器

我正在使用Rub On Rails 4.x编写程序,我必须使用已填写的已定义字段的PDF文件,从表单提交中填写数据(此部分已完成!),最后允许用户修改保存的PDF文件在服务器上,并在进行修改后覆盖所述PDF。 就像我说的那样,我已经通过pdftk填写了表格中提交的PDF文件。 我现在需要做的是为从该过程的第一步生成的服务器上的所述PDF文件提供服务器端编辑function。 我见过类似的post,但没有人想做我做同样的事情。 如果我错了,链接会很棒。 在此先感谢您的帮助!

lib文件夹中的模块类

我有一个lib文件lister_extension.rb module ListerExtension def lister puts “#{self.class}” end end 并发布模型 class Post < ActiveRecord::Base has_many :reviews extend ListerExtension def self.puts_hello puts "hello123123" end end 当我在rails c调用它时一切都很好: 2.1.1 :003 > Post.lister Class => nil 但是当我想在我的模块中添加一个类时会发生什么? 例如: module ListerExtension class ready def lister puts “#{self.class}” end end end 我收到这个错误 TypeError: wrong argument type Class (expected Module) 当我在rails […]

是否可以增强rake测试任务并将测试结果合并在一起?

我正在为我的sidekiq工人编写测试,我希望他们在终端输入“rake”时运行。 我有这个工作 – 我将以下内容添加到我的Rakefile中: namespace :test do Rake::TestTask.new(:workers) do |t| t.libs << "test" t.pattern = 'test/workers/**/*_test.rb' end end Rake::Task[:test].enhance ["test:workers"] 当我运行rake时,我得到这样的东西作为我的输出: Run options: –seed 51172 # Running tests: SS Finished tests in 0.005594s, 357.5259 tests/s, 0.0000 assertions/s. 2 tests, 0 assertions, 0 failures, 0 errors, 2 skips Run options: –seed 17561 # Running tests: S……………………………………..SSSS..SSSSS…… […]

类别,子类别和律师之间的关联

我有很多律师,类别和子类别。 提示 (如果我的协会合适 ,你可以有一个线索) 在类别表上,我不希望在类别表上看到引用子类别的列。 在子类别表上,我不希望在Subcategories表上看到引用类别的列。 并非所有类别都有子类别。 即一些没有图中所示的子类别。 我有2个单独的表单创建类别和子类别。 我将category_id和subcategory_id作为外键添加到我的律师表中。 这样我就可以在创建时选择律师forms,律师将在图像中尽快选择类别或子类别。 另请注意:对于没有子类别的类别,可以在任何时间,任何一天创建子类别,以及已经具有某些子类别的类别下的新子类别,并且律师将被置于其下。 图像是我目前正在进行的索引/主页的复制品,至少在上面的第6个上面任何时候生效,我希望使用循环来实现这个视图。 图解理解我想要做的事情: 这是我在3个模型之间的关系 class Lawyer < ActiveRecord::Base belongs_to :category belongs_to :subcategory end class Category < ActiveRecord::Base has_many :lawyers end class Subcategory < ActiveRecord::Base #belongs_to :category #Do I want "category_id" in Subcategories Table? has_many :lawyers end 题 我在这3个型号上的关联是否适合我提供的提示? 这非常令人困惑。

使用自定义URL(例如http:// localhost:3000 / education_informations / new?user_id = 10)在新页面上呈现错误

我正在尝试使用新操作http:// localhost:3000 / education_informations / new?user_id = 10传递查询参数,并在其上设置表单validation。 当表单提交失败,所以它的显示错误,但url更改为http:// localhost:3000 / education_informations所以我想同样自定义url并使用user_id传递查询参数。 请帮我 控制器代码给出如下 def create @edu_info = EducationInformations.new(educational_params) if @edu_info.save #flash[:notice] = ‘Vote saved.’ redirect_to @edu_info else render ‘new’ end end

Rails – 如何找到某个列值为nil的所有行where()

我想返回一个数组,其中包含一个名为bookings的表中的所有行,其中bookings空。 到目前为止,我已经尝试过Booking.where(“returned_date ””) ,它选择了存在returned_date的所有记录,但我希望对此进行反向选择。

如何设计销毁会话并从控制器注销?

设计销毁会话并从控制器退出? if something_is_not_kosher # 1. log this event, 2. send notice redirect_to destroy_user_session_path and return end 还尝试过: if something_is_not_kosher # 1. log this event, 2. send notice redirect_to controller: ‘devise/sessions’, action: ‘destroy’, method: :delete and return end 错误是No route matches [GET] “/users/sign_out”但我明确设置方法::在示例2中删除。也许设计有一个方法? current_user.sign_out并试过sign_out(current_user)哪个也行不通? 谢谢您的帮助。 耙路线: new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE […]

使用带远程的ajax的Ruby表单:true给出了ActionController :: InvalidAuthenticityToken错误。 经典提交没有

我正在为一个RoR网站写一个聊天页面。 我已经完成了所有HTML和我试图用ajax实现它。 有一个提交消息的表单。 表单标签读取 true) do |f| %> true) do |f| %> 我的整个观点: Battleriskopoloy – Communications [ . . . Communications . . . ] “select”, :method => :get %> true) do |f| %> 控制器: class ChatsController < ApplicationController $messeges = Array.new(10, " ") def new $messeges = Array.new if $ruser != nil $messeges = […]