Tag: ruby on rails 4

Rails的link_to_function弃用状态?

Rails中link_to_function Javascript助手的状态是什么? 我读过,包括在这个stackoverflow问题中 ,它在Rails 3.0中被弃用,然后是不推荐的,然后在3.2.4中再次弃用。 这是我可以依赖并教导学生的东西吗? 我刚刚阅读了Rails 3.2.8的发行说明(来自搜索) : 恢复了button_to_function和link_to_function助手的弃用。 RafaelMendonçaFrança 现在这个立场在哪里?

将枚举值映射到字符串类型而不是整数的可能性

枚举属性很棒,我想使用它们。 但是将枚举值映射到整数将使得难以维护代码和数据库。 此外,我的数据库将与我的代码高度耦合,我认为我应该认为这是一件坏事。 我知道我可以使用哈希来组织具有键/值对的枚举属性,但是能够使用数组并映射到数据库中的字符串值仍然会好得多。 有默认情况下将枚举映射到字符串的方法吗?

生成带有图像的pdf时,PDFkit会挂起

我想将网页呈现为PDF。 它使用单个图像,我已经读过你需要提供PDFkit的绝对URL才能使用图像,所以我的代码是: = image_tag image_url(user.avatar) 这在以HTML格式查看时有效,并且PDFkit能够生成删除了图像的PDF。 但是,在使用图像时,它会挂起,直到我杀死服务器。 我怎样才能让它发挥作用? 这是杀死服务器时的完整输出: 2013-12-04 13:53:36.576 wkhtmltopdf[27410:507] CoreText performance note: Client called CTFontCreateWithName() using name “Arial” and got font with PostScript name “ArialMT”. For best performance, only use PostScript names when calling this API. 2013-12-04 13:53:36.577 wkhtmltopdf[27410:507] CoreText performance note: Set a breakpoint on CTFontLogSuboptimalRequest to debug. 2013-12-04 13:53:36.582 wkhtmltopdf[27410:507] […]

无法在Ruby on Rails上安装Puma gem

我正在尝试安装美洲狮gem,但是当我跑的时候 gem install puma 我收到此错误消息: Temporarily enhancing PATH to include DevKit Building native extensions. This could take a while… ERROR: Error installing puma: ERROR: Failed to build gem native extension. C:/Ruby193/bin/ruby.exe extconf.rb creating Makefile make generating puma_http11-i386-mingw32.def compiling http11_parser.c ext/http11/http11_parser.rl: In function ‘puma_parser_execute’: ext/http11/http11_parser.rl:111:3: warning: comparison between signed and unsigned integer expressions compiling io_buffer.c io_buffer.c: […]

允许用户在Devise中添加新用户,并保持自己登录

我使用Ruby On Rails与Devise,Rails 4.1.0.rc1,Ruby 2.1.0p0,devise-3.2.4 我按照Rails Cast Episode#209的教程来安装和使用设计。 我可以登录并注销并注册新用户。 我扩展了我的用户模型,以包含生日,名字和姓氏等不变信息。 在这篇博客文章之后,我添加了一个用户控制器和视图,以便添加其他function,例如我没有用设计看到的所有用户的列表。 https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users 我还回顾了关于堆栈溢出的这些问题: 允许管理员使用Devise添加用户 如何在Devise中自定义控制器以进行注册? Ruby on Rails:自定义设计注册控制器,请求创建操作 从今年3月1日开始,我是ruby on rails的新手,并参加了Mike&Nicole Clarks Rails 1&Rails 2在线课程。 我想要做的是允许用户添加新用户。 最终,此function将是添加客户端的管理员或经理。 然后,客户端应该能够使用创建的凭据登录。 发生的事情是我可以登录,通过new_user_path和用户视图添加新的“用户”(而不是设计视图),但是当我提交它时,我将以新用户身份登录。 以前的用户不是持久的。 我通过用户视图和控制器操作执行所有这些操作,因为我不想实际“注册”或使用这些操作登录和注销,只需在用户表中创建新记录,然后就可以登录到他们的拥有。 任何帮助表示赞赏。 这是我的用户控制器: class UsersController < ApplicationController def index @users = User.all end def show @user = User.find_by_id(params[:id]) end def new @user = User.new end […]

rails不会将send_data作为文件

我遇到了Rails方法的问题: send_data 这是我的行动: def export send_data(current_user.contacts.to_csv, type: ‘text/csv; charset=utf-8; header=present’, disposition: ‘attachment; filename=contacts.csv’ ) end 这不会促使下载,它只是在屏幕上呈现结果。 我已经尝试过pow和thin服务器。 我无法弄清楚我做错了什么? 我正在使用rails 4.0.0.beta 编辑: CURL标题: < HTTP/1.1 200 OK < X-Frame-Options: SAMEORIGIN < X-XSS-Protection: 1; mode=block < X-Content-Type-Options: nosniff < X-UA-Compatible: chrome=1 < X-XHR-Current-Location: /contacts/export < Content-Disposition: attachment; filename=contacts.csv < Content-Transfer-Encoding: binary < Content-Type: text/csv; charset=utf-8; header=present < […]

javascript_include_tag会抛出不受支持的方法

我最近使用Rails 4.2.0创建了一个新项目,并为着陆页创建了一个名为Land的控制器。 所以,我在访问http://localhost:3000/land/home时遇到了这个错误: Started GET “/” for ::1 at 2015-02-27 15:56:23 -0600 Processing by LandController#home as HTML Rendered land/home.html.erb within layouts/application (0.0ms) Completed 500 Internal Server Error in 5526ms ActionView::Template::Error (TypeError: Object doesn’t support this property or method (in C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)): 3: 4: Course 5: true %> 6: 7: 8: 9: app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__1279127835_98590860′ Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_source.erb (5.0ms) […]

Param丢失或值为空:ResultsController#update中的ParameterMissing

我有一个属于网站的结果。 创建网站后,我还创建了结果并重定向到其编辑页面。 在这里,我想添加一些更多的值。 我的问题是:当我尝试更新我的结果时,我得到: param is missing or the value is empty: result Request Parameters: {“utf8″=>”✓”, “_method”=>”patch”, “authenticity_token”=>”GRN/y/04Qbsm9DzlUAbUYF8ZSv2EMHnRZgBZY/6GMDlOBdq8V5Uncij9VRp51uydC6M/qc61jPWwpUehSuc5xA==”, “data”=>[“//html/body/div[position() = 3]/ul/li[position() = 16]/ul/li[position() = 2]/child::text()”, “//html/body/div[position() = 3]/ul/li[position() = 16]/ul/li[position() = 2]/p/a/child::text()”, “//html/body/div[position() = 3]/ul/li[position() = 16]/ul/li[position() = 4]/child::text()”, “//html/body/div[position() = 3]/ul/li[position() = 16]/ul/li[position() = 5]/a/child::text()”], “commit”=>”Update Result”, “id”=>”66”} 这就是我的结果参数的样子 def result_params params.require(:result).permit(:data) end 我的模特: […]

Rails:AbstractController :: Helpers :: MissingHelperError – 缺少帮助文件application_helper.rb_helper.rb

找不到任何帮助我的资源! 当我尝试’rails s’并转到应用程序的任何页面时; 它向我发送这个错误页面说我缺少帮助文件。 我认为它在我的台式机上是本地的,因为我最近在笔记本电脑上对应用程序做了一些工作。 我推出笔记本电脑和应用程序在Heroku上工作正常,并在该机器上运行本地零问题。 我添加了一项function,使用Carrierwave,Mini_Magick和Fog将公司徽标图像上传到Amazon S3。 到目前为止我尝试过的事情:我删除了应用程序并将git克隆回到这台机器上。 我已经尝试过Brew卸载/安装imagemagick,并在克隆应用程序后完成了所有基础知识,例如bundle install,rake db:migrate。 仍然没有运气.. 这是我在页面上获得的错误代码以及完整的跟踪: AbstractController::Helpers::MissingHelperError in PagesController#dashboard Missing helper file helpers//users/jamesfend/sites/feedbackz/app/helpers/application_helper.rb_helper.rb Extracted source (around line #1): 1 class ApplicationController < ActionController::Base 2 # Prevent CSRF attacks by raising an exception. 3 # For APIs, you may want to use :null_session instead. 4 protect_from_forgery with: :exception […]

ActionDispatch :: Request的未定义方法`flash’

我正在尝试在Rails 4中编写一个Ember应用程序,并决定使用rails-api作为api控制器,同时保持应用程序控制器完好无损的几页不属于单页面应用程序。 换句话说,这是我的控制器: app/controllers/application_controller.rb : class ApplicationController < ActionController::Base protect_from_forgery end app/controllers/sample_controller.rb : class SampleController < ApplicationController # my methods end app/controllers/api/v1/api_controller.rb : class Api::V1::ApiController < ActionController::Api include ActionController::MimeResponds end app/controllers/api/v1/sample_controller.rb : module Api::V1 class SampleController < ApiController respond_to :json # my methods end end 我的application.html.slim包含以下行: == render partial: “flash_msgs” unless flash.blank? 包含哪个会导致以下错误: 未定义的方法’flash’用于# 根据这个线程的讨论,似乎罪魁祸首可能是rails-api […]