Tag: ruby on rails 4

Typicons字体没有在heroku中显示

我在我的rails应用程序中使用typicons和heroku并且它在本地工作但不在生产中,我在heroku中没有得到任何路由错误,我不确定我缺少什么。 我在资源文件夹中有一个字体文件夹,我正在使用 config.assets.paths << Rails.root.join("app", "assets", "fonts") 在我的应用程序类下的config.application.rb文件中。 在typicons.css.scss里面(在stylesheets文件夹中)我有 @font-face { font-family: ‘typicons’; src: font-url(‘typicons.eot’); src: font-url(‘typicons.eot?#iefix’) format(’embedded-opentype’), font-url(‘typicons.woff’) format(‘woff’), font-url(‘typicons.ttf’) format(‘truetype’), font-url(‘typicons.svg#typicons’) format(‘svg’); font-weight: normal; font-style: normal; }

Rails PG HABTM的关系

我有一个事实表,客户有很多业务: bus_id, sales, date 1, $986, 1/1/2016 1, $543, 1/2/2016 2, $921, 1/1/2016 2, $345, 1/2/2016 我想创造一个表机会 bus_id, opportunity 1, “Upsell” 1, “Upsell More” 如何创建两者之间具有has_and_belongs_to_many关系的opportunity表,以便它们在bus_id外键上链接?

将国家标志纳入Rails 4应用程序有哪些选择?

现在我正在我的用户模型中使用country_select gem和countries gem以及:country列。 我想使用@user.country显示每个@user的国旗。 world-flags gem在4年内没有更新,被列为Rails 3,StackOverFlow几乎没有任何关于它的内容。 或者我想我可以下载这些标志png将它们放在s3上的文件夹中并执行以下操作: def flag_url self[country] = /flags/”#{country}”.png end

pdfkit的image和print_media_type无法在rails 4.0.2上运行

我使用pdfkit创建了一个pdf.Pdf已创建。 但是我的pdf上没有显示图像,print_media_type也无法正常工作。 我使用的是rails 4.0.2和ruby 2.0.0。 有谁可以帮我解决这个问题? 我在这里附上细节。 谢谢。 gem文件: gem ‘pdfkit’,’0.5.2′ gem ‘wkhtmltopdf-binary’,’0.9.9.1′ gem ‘wkhtmltopdf-heroku’,’1.0.0′ application.css: @media print { body { text-align: justify; font-size:566px; background-color: red; } } application.rb中: require “pdfkit” config.middleware.use PDFKit::Middleware, :print_media_type => true config / initializers / pdfkit.rb: PDFKit.configure do |config| config.wkhtmltopdf = ‘C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe’ config.default_options = { :page_size => ‘A4’, :page_height […]

从Rails调用Uber API:{“error”:“invalid_client”}

在这一天。 使用Rails调用Uber API并且无法获取访问令牌。 抓取授权代码可以正常工作,但是交换访问令牌则不行。 我尝试过使用和不使用OAuth 2.0 gem并确保所有密钥都准确无误。 也试过两个独立的优步账户。 所有组合都会出现相同的错误: {“error”: “invalid_client”} 。 我将在下面发布非OAuth代码。 params[:code]是Uber返回的auth代码。 uri = URI.parse(‘https://login.uber.com/oauth/v2/token’) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true headers = { # authentication content-type is not json # ‘Content-Type’ => ‘application/x-www-form-urlencoded’, ‘Authorization’ => ‘Token ‘ + @server_token } request = Net::HTTP::Post.new(uri.path, headers) request.set_form_data({ ‘client_id’ => @client_id, ‘client_secret’ => @client_secret, […]

使用控制器的Rails 4关注DRY更新方法

我有一个rails应用程序,其中许多模型可以使用best_in_place进行编辑,所以我有很多看起来像这样的控制器: before_action :find_objects, except: [:new, :create] def update @object.update_attributes(object_params) respond_to do |format| format.json { respond_with_bip @object} end end private def object_params params.require(:object).permit(:foo, :bar) end def find_objects @object = Object.find(params[:id]) end 如果要更新的对象将在params散列中使用特定名称,并且object_params和find_objects应根据模型名称调用其正确的版本,如何将此特定重复的片段移动到控制器关注中? 是否有一些优雅的元魔法可以解决这个问题?

Rails 4 – 嵌套模型(2级)不保存

关于嵌套模型的Noob问题。 我正在使用Rails 4并尝试创建嵌套模型,如下所示: 调查有很多问题每个问题有很多答案 我正在关注Rails Casts第196集以相同的forms创建调查,问题和答案。 Surevey和Realted问题得到保存,但答案不会保存到数据库中。(但是答案字段显示正确。) 我非常感谢您对此的投入。 谢谢,迈克 surveys_controller.rb def index @surveys = Survey.all end def new @survey = Survey.new 3.times do question = @survey.questions.build 1.times { question.answers.build } end end def create @survey = Survey.new(survey_params) respond_to do |format| if @survey.save format.html { redirect_to @survey, notice: ‘Survey was successfully created.’ } format.json { render […]

Rails 4 – 研究不显示

我有一个应用程序列出一些“Tuto”,我希望用户可以按类别或关键字搜索任何Tuto。 它就像关键字的魅力,但不适用于类别…… 即使我选择一个类别,一切仍然显示… 类别是在控制台中创建的,如Category.create(name: “Ruby”)等等…… 这是我的观点索引 .container .row h1.text-gray Tutorials .row.search_banner .col-xs-3 =form_tag tutos_path, :method => ‘get’ do =text_field_tag :search, params[:search], placeholder:”Search by keywords” =submit_tag “Search”, class:’btn btn-xs btn-default btn-search’ .col-xs-3 =form_tag tutos_path, :method => ‘get’ do =select_tag :filter, options_for_select(Category.all.map{|c| c.name}, params[:filter]) =submit_tag “Search”, class:”btn btn-xs btn-default btn-search” .col-xs-3 -if user_signed_in? = link_to “Create a […]

button_to表单提交在浏览器中工作但是没有rspec / capybara测试,路由错误

我正在使用rspec和capybara编写集成测试,用于覆盖现有function的rails4应用程序(当我第一次编写应用程序时,我很懒)。 以下提交按钮在浏览器(Chrome)中正常工作,并重定向到成功页面(如预期的那样) “open-contacts-dialog-btn”, :class => “inbox-sf-add-btn tip”, :style => “background:lightgreen” %> 但是,以下测试失败, describe “should show confirmation message after submitting the form” do it “should go to success message when form submitted” do click_link ‘See more details’ click_button ‘Sign Me Up!’ fill_in ‘Email’, with: “simon@example.com” fill_in ‘attendee_name’, with: “Simon T” fill_in ‘attendee_phone’, with: “1234567890” fill_in ‘attendee_num_guests’, […]

rails路由:id无效

我有一个名为Schedule的模型属于一个项目。 一个项目有一个时间表。 我试图遵循CRUD惯例,但有一些困难。 我有一个列出所有项目的页面,并在每个项目旁边都有一个链接来创建计划。 我在路径文件中开始使用以下内容: resources :schedules 这是问题所在。 在“新计划”页面的url中,需要有一个:id,指的是计划所属的项目,当创建计划时,它将属于正确的项目。 我不知道如何用资源做到这一点,所以我将路由代码更改为: match ‘schedules/new/:id’, to: ‘schedules#new’, as: :new_schedule, via: [:get, :post] resources :schedules, except: [:new, :create] 出于某种原因,此页面为空白。 它只是白色的。 如何修复路线? 谢谢。 更新: 我也尝试将我的路线更改为以下内容: resources :projects do resources :schedules end 这使得新计划的URLforms为: /projects/:project_id/schedules/new(.:format) 我认为这是应该如何完成的,但是,新计划的表格是写成的 form_for @schedule 并产生以下错误: undefined method `schedules_path’ 有任何想法吗?