ruby-on-rails-3

Get and display all values from database row separately based on select (Rails)

送分小仙女□ 提交于 2020-01-25 20:30:34
问题 Hi i'm stuck making an invoicing application. I want to have an option where you can add an existing customer from the customers table and add those values to the invoice. The values i want to display are company_name , vat_number and iban_number . I tried doing this: <%= select_tag 'choose customer', options_from_collection_for_select(current_user.customers.all, 'id', 'company_name') %> But obviously this only gets the value of company_name . I tried using collection.select but that one also

Ruby on Rails paperclip questions

霸气de小男生 提交于 2020-01-25 20:15:08
问题 I want to use paperclip to upload files to server. Errors are all cleaned now, but I don't know how to set the upload path. My code looks like this: upload class: puts has_attached_file :image, :default_url => :file_system validates_attachment_content_type :image, :content_type => [:image, 'audio/mpeg', 'application/mp3', 'application/octet-stream'] I want to save uploads in project/public/uploads. How can I realise this? 回答1: Then it should look like this: has_attached_file :image, :path =>

Rails content_tag inserts extra “<” and “>” characters

孤街醉人 提交于 2020-01-25 13:16:08
问题 When doing this: def user_log if logged_in? == false form_tag session_path, :id => "mform" do content_tag(:span, content_tag(text_field_tag :email, "email@domain.com"), :class => "memail")+ content_tag(:span, content_tag(password_field_tag :password, "12345678912"), :class => "mpass")+ content_tag(:span, content_tag(submit_tag 'Login'), :class => "mbutton") end else ... end end end I get this: stack overflow doesn't let me post pictures Since I don't want the extra "<" and ">", what am I

DeprecationWarning: 'root' is deprecated, use 'global'

自闭症网瘾萝莉.ら 提交于 2020-01-25 12:53:05
问题 I am working on project and stuck at a point where i got this error unexpected token at '(node:14500) [DEP0016] DeprecationWarning: 'root' is deprecated, use 'global' because I have used JavaScript tag at the end of the view file. Moreover if I use application JavaScript file instead of admin/admin then it works fine but i need to use admin layout script file. So how can I fix this issue ? 来源: https://stackoverflow.com/questions/54036700/deprecationwarning-root-is-deprecated-use-global

Iterating the dates in ruby on rails

﹥>﹥吖頭↗ 提交于 2020-01-25 12:13:05
问题 I am developing an application for reporting and analytic,where I need to generate data on a daily basis and put it in a CSV.To be more clear, if I take the report today like day one any how I can get the report thats already done, if I get the report tomorrow I should be able to get the data of today,yesterday. If i take after 4 days I should get the report starting from day 1 to day 4. How it can be done. Looking for heads up 回答1: How about this: today = Date.today tomorrow = today.next

How to read from a file & store key:value pair in String Array?

 ̄綄美尐妖づ 提交于 2020-01-25 11:32:00
问题 I have a coffee script file with the following data in it. I want to create a string array that will store the following data as key:value pair in it. abTests: productRanking: version: 4 groups: [ ratio: default: 1 us: 0.90 me: 0.0 value: "LessPopularityEPC" , ratio: default: 0 us: 0.1 value: "CtrEpcJob" , ratio: default: 0 me: 1.0 value: "RandomPerVisitor" ] sabt: version: 1 groups: [ ratio: default: 1 us: 0.90 value: "default" , ratio: default: 0 us: 0.05 value: "colorBoost" , ratio:

How to read from a file & store key:value pair in String Array?

大憨熊 提交于 2020-01-25 11:31:46
问题 I have a coffee script file with the following data in it. I want to create a string array that will store the following data as key:value pair in it. abTests: productRanking: version: 4 groups: [ ratio: default: 1 us: 0.90 me: 0.0 value: "LessPopularityEPC" , ratio: default: 0 us: 0.1 value: "CtrEpcJob" , ratio: default: 0 me: 1.0 value: "RandomPerVisitor" ] sabt: version: 1 groups: [ ratio: default: 1 us: 0.90 value: "default" , ratio: default: 0 us: 0.05 value: "colorBoost" , ratio:

Rails time zone from URL params

廉价感情. 提交于 2020-01-25 11:24:06
问题 I'm trying to allow non-signed-in users to change a time of day display, and it seems like the best way would be through params in the url. I have: class ApplicationController < ActionController::Base around_filter :use_time_zone private def use_time_zone(&block) Time.use_zone((params[:time] || Time.zone), &block) end end And this works great for something like 'www.mysite.com?time=Hawaii' However, it cannot handle some of the more intricate ones (e.g. 'Eastern Time (US & Canada)'), plus this

Changing URL in the web page

删除回忆录丶 提交于 2020-01-25 11:15:05
问题 How could i change the URL address while i'm moving from one tab to another tab within the same page? Where i want to change the code either in the routes.rb or in controller? routes.rb: Rails.application.routes.draw do resources :dashboard, only: [:index] resources :profile do collection do patch 'update_profile' patch 'change_password' end end devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } root 'dashboard#index' end My current url is localhost:3000

will_paginate and .sort =>

蓝咒 提交于 2020-01-25 05:36:49
问题 I recently got the will_paginate gem installed and it works great, but I would like it to work with the setup I currently have. Right now I show all feeds (or posts) on the same page, but they are sorted after how many people clicked on that page: controller.rb @t = Time.now @h1 = @t - 1.hour @feeds = Feed.find(:all, :order => "created_at DESC").sort { |p1, p2| p2.impressionist_count(:filter=>:all, :start_date=>@h1) <=> p1.impressionist_count(:filter=>:all, :start_date=>@h1)} Now... I tested