ruby-on-rails-3

“\xC4” from ASCII-8BIT to UTF-8 when running rake db:migrate on Heroku

三世轮回 提交于 2019-12-24 09:28:23
问题 When I try to run heroku run rake db:migrate in my application, I get the following error "\xC4" from ASCII-8BIT to UTF-8 with a stacktrace of /app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `write' /app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `puts' /app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `display_error_message' /app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:142:in

Rails 3 routing how to match multiple?

大憨熊 提交于 2019-12-24 09:28:05
问题 How do I match multiple controller for example an id? I have tried this in my routes: match '/:id' => 'kategoris#show' match '/:id' => 'tags#show' 回答1: Rails controller routing isn't appropriate for you if you're wanting to match http://example.com/<something> . You could create a single ThingsController: match '/:id' => 'things#show' and then do something appropriate in your ThingsController. Eg. in Sinatra (which you could mount as a Rack middleware) you'd do this: get "/:id" do :id if(@tag

Rails - Scalable calculation model

情到浓时终转凉″ 提交于 2019-12-24 09:12:45
问题 I currently have a calculation structure in my rails app that has models metric , operand and operation_type . Presently, the metric model has many operands , and can perform calculations based on the operation_type (e.g. sum, multiply, etc.), and each operand is defined as being right or left (i.e. so that if the operation is division, the numerator and denominator can be identified). Presently, an operand is always an attribute of some model, e.g. @customer.sales.selling_price.sum . In

How to return nested comments using API in Rails

好久不见. 提交于 2019-12-24 09:07:59
问题 Each Car has has_many :comments association I have following method to return my cars: class Api::V1::CarsController < Api::V1::BaseController def recent recent = Car.most_recent(params[:how_recent]) comments = recent.each{|r| r.comments} ## ?? respond_with(:recent => recent) end end I get recent cars by: curl -X GET http://cars.dev/api/v1/cars/recent -d "token=zzxWkB3SzDP3U1wDsJbY" -d "how_recent=20" And I would like to get response like that: "recent_with_comments":{"recent":[{"type":

Does anyone know a js lib for dynamic tables with pagination?

早过忘川 提交于 2019-12-24 09:07:02
问题 I have created a rails controller that returns JSON data. So, I cannot render the data on the server as usual with rails. I can create a simple JS that can just take the JSON and create a table. But I which to support pagination. I looked a few such tables from jquery plugins but they do not use Bootstrap css, so it looks pretty nasty in my layout. Has anyone encountered such a problem? 回答1: I'd recommend you using Backbone and Backbone.Paginator. Fits your needs perfectly! 来源: https:/

How to perform 301 before force_ssl? Rails 3.1

时光总嘲笑我的痴心妄想 提交于 2019-12-24 08:59:49
问题 I need to make http://example.com go to https://www.example.com. right now it's warning in the browser. I followed: http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/ loading from /lib/middleware (Rails 3.1) class WwwMiddlewareRedirect def initialize(app) @app = app end def call(env) request = Rack::Request.new(env) if request.host.starts_with?("example.com") [301, {"Location" => request.url.sub("//", "//www.")}, self] else @app.call(env) end end def each(&block) end

Job failed to load: uninitialized constant Syck::Syck

北慕城南 提交于 2019-12-24 08:25:53
问题 I am running a method in the background using delayed-job (collectiveideas fork) The method I am running is shown below, which fetches the price of the isbn: def update_prices(isbn13) @amazon = Nokogiri::XML(open("http://www.amazon.com/s/?url=search-alias%3Daps&field-keywords=#{isbn13}")) price = @amazon.search('span.listprice').first.text.gsub('$', '') book = Book.find_by_isbn13(isbn13) book.update_attribute(:amazon_us_price, price) end handle_asynchronously :update_prices Now when I run

How to generate custom sorted query string URL in Rails link_to?

♀尐吖头ヾ 提交于 2019-12-24 08:25:42
问题 When I use link_to helper in Rails 3.0.7 app with many parameters, it generates a lexicographically sorted url as probably mentioned in the to_param method for Hash in Activesupport documentation. e.g. link_to "my Link", {:u=>"user", :q=>"some query", :page=>"4"} generates "/search?page=4&q=some+query&u=user" but what i want is "/search?u=user&q=some+query&page=4" Anyone able to do custom sorting as supplied in the params hash to link_to or url_for ? Unless I am missing something, this seems

html is being escaped in link_to

人走茶凉 提交于 2019-12-24 08:23:10
问题 I'm trying to implement a link, when clicked marks you as present for a meeting. This link is a method in a helper: def link_to_remote_registration(event_id) down_image = "down_blanco.png" up_image = "up_blanco.png" unless registration.nil? if registration.present == 1 up_image = "up_filled.png" elsif registration.present == 0 down_image = "down_filled.png" end end link_to_remote_registration = String.new loading_and_complete = "Element.show('indicator_event_"+event_id.to_s+"'); Element.hide(

Rails controller path not found

那年仲夏 提交于 2019-12-24 08:20:55
问题 My form tag in my view: <%= form_tag view_all_rater_path, :method => 'get' do %> <p> <%= text_field_tag :search, params[:search], :placeholder => 'Search by Set # or date' %></br> <%= submit_tag "Search", :class => "btn btn-link", :name => nil %> </p> <% end %> My controller action: def view_all if params[:search] @ratings = RatingSet.find(:all, :conditions => ['id = ? or rating_date like ?', "%#{params[:search]}%"]) else @ratings = RatingSet.all end end My routes: resources :rater, :only =>