ruby-on-rails-3

404 error with open-uri in a rake task… what's causing it?

情到浓时终转凉″ 提交于 2020-01-01 08:04:09
问题 I have a rake task that fetches JSON data from an API, parses it, and saves it to the database: task :embedly => :environment do require 'json' require 'uri' require 'open-uri' Video.all.each do |video| json_stream = open("http://api.embed.ly/1/oembed?key=08b652e6b3ea11e0ae3f4040d3dc5c07&url=#{video.video_url}&maxwidth=525") ruby_hash = JSON.parse(json_stream.read) thumbnail_url = ruby_hash['thumbnail_url'] embed_code = ruby_hash['html'] video.update_attributes(:thumbnail_url => thumbnail_url

What is the difference between render and yield in Rails

倾然丶 夕夏残阳落幕 提交于 2020-01-01 08:03:52
问题 Can someone explain the difference between " <%= render %> " and " <%= yield %> with <% content_for :partial do %> / <% end %> "? specifically how the routing changes when switching from one to another, the benefits of using one over the other, when is it practical to use one over the other. THIS is the closest explanation I have found, but isn't quite clear enough for me. I have been trying for several days to wrap my head around this, but it seems that each configuration I try either comes

Reverse pagination with kaminari

旧城冷巷雨未停 提交于 2020-01-01 07:53:25
问题 I want to create pagination for a messaging system in which the first page shown contains the oldest messages, with subsequent pages showing newer messages. For example, if normal pagination for {a,b,c,d,e,f,g,h,i} with 3 per page is: {a,b,c}, {d,e,f}, {g,h,i} Then reverse pagination would be: {g,h,i}, {d,e,f}, {a,b,c} I plan to prepend the pages so the result is the same as normal pagination, only starting from the last page. Is this possible with kaminari ? 回答1: There's a good example repo

Where to test routes in ruby on rails

我是研究僧i 提交于 2020-01-01 07:39:10
问题 Where to test routes in ruby on rails? unit tests? functional tests? integration tests? Addition: To be exact, where to apply assertions described on guides and on api? 回答1: Routes should be done as part of integration tests. Integration tests are where you test the important work flows of your application - more specifically whether a URL is defined or not seems to be an important workflow. Your integration test would look like any normal integration test: # /tests/integration/routes_test.rb

Rails Nested Singular Resource Routing

可紊 提交于 2020-01-01 07:37:06
问题 I have a simple User model with a singular nested Profile resource so in my routes.rb I have: resources :users do resource :profile, :only => [:edit, :update, :show] end This generates the expected routes: edit_user_profile GET /users/:user_id/profile/edit(.:format) {:action=>"edit", :controller=>"profiles"} user_profile GET /users/:user_id/profile(.:format) {:action=>"show", :controller=>"profiles"} user_profile PUT /users/:user_id/profile(.:format) {:action=>"update", :controller=>"profiles

Omniauth Facebook Manual Rails Routes

流过昼夜 提交于 2020-01-01 07:34:12
问题 I am trying to use Omniauth facebook with two devise models in a Rails 3 app. Currently that's not something that's possible using omniauthable and the devise helpers. A similar question answered how to do this: Omniauth "with" STI and devise "..move your omniauth configuration from devise.rb to omniauth.rb and create your own omniauth routes.' But I am having trouble in defining these routes and helpers, i.e. for facebook I used a devise helper like this: user_omniauth_authorize_path(

Rails - Using Tempfile to write on Heroku?

懵懂的女人 提交于 2020-01-01 06:58:25
问题 I need to be able to write a temporary file for use during the request only. Locally I can use the following successfully: tempfile = File.open(a.original_filename,'w') tempfile.write_nonblock(a.body) paperclip stuff........ tempfile.close That works great, but not on Heroku... How can I do the above with Heroku's restrictions: link text I'm not understanding how to translate the above into: #{RAILS_ROOT}/tmp/myfile_#{Process.pid} Thanks for any help you can provide here. 回答1: I have a

Rails - Is there a shortcut to pass all existing params?

人盡茶涼 提交于 2020-01-01 06:58:12
问题 How can you pass all parameters to a controller action? # instead of: <%= link_to mylist_url(id: params[:id], se: "true", st: params[:st], re: params[:re], li: params[:li]) do %> ... <% end %> # something like: <% link_to mylist_url(params: :all, se: "true") do %> ... <% end %> 回答1: Can you just use Hash#merge?, something like: <% link_to mylist_url(params.merge(:se=>"true")) do %> ... <% end %> 来源: https://stackoverflow.com/questions/4112425/rails-is-there-a-shortcut-to-pass-all-existing

Rails - Is there a shortcut to pass all existing params?

左心房为你撑大大i 提交于 2020-01-01 06:58:05
问题 How can you pass all parameters to a controller action? # instead of: <%= link_to mylist_url(id: params[:id], se: "true", st: params[:st], re: params[:re], li: params[:li]) do %> ... <% end %> # something like: <% link_to mylist_url(params: :all, se: "true") do %> ... <% end %> 回答1: Can you just use Hash#merge?, something like: <% link_to mylist_url(params.merge(:se=>"true")) do %> ... <% end %> 来源: https://stackoverflow.com/questions/4112425/rails-is-there-a-shortcut-to-pass-all-existing

How to include SSL Certificate in Rails 3 project

。_饼干妹妹 提交于 2020-01-01 06:55:49
问题 I have developed a Rails 3 project which uses thin as server, along with Devise and Doorkeeper for Authentication I would like to add SSL Certificate in my project. I have seen some posts which describes how to use SSL Certificate in Rails 3 Project,but none of then showing how to add certificate in Rails 3 project. I have enabled config.force_ssl = true in my applicationcontroller.rb , and I tried starting thin server like: thin start --ssl It works without adding certificate and I can now