ruby-on-rails-3.1

ActiveRecord::RecordNotFound - Couldn't find User without an ID

送分小仙女□ 提交于 2019-12-31 05:03:06
问题 Following Hartl's RailTutorial for Rails(3.2). I keep getting this error message or oddly a "The connection was reset" message: ActiveRecord::RecordNotFound in UsersController#show Couldn't find User without an ID I'm trying to log in and after successfully logging in, I want the application to redirect the user to user/show.html.erb. I believe that I'm passing the :id parameter in the show method in the users controller. Any tip/help would be appreciated! I've pasted some relevant files

how to use link_to with ajax in rails 3.2.1

喜夏-厌秋 提交于 2019-12-31 04:44:06
问题 I m using Rails 3.2.1 . how to use link_to with remote=>true My Method in Controller def clickme @clk = "you click me" respond_to do |format| format.js { render :layout=>false } end end My View In my new.html.erb file <%= link_to "click here", {:action=>"clickme"}, {:remote => true, :id=>"clk"} %> <div id="allclick"> <%= render :partial => 'goclick' %> </div> _goclick.html.erb <%= @clk %> clickme.js.erb $("allclick").update("<%= escape_javascript(render(:partial => "goclick")) %>"); On my web

Rails 3.1.0, geokit, with error acts_as_mappable

邮差的信 提交于 2019-12-31 04:43:05
问题 I am getting the undefined local variable or method `acts_as_mappable' error when using geokit, and after tons of Goggling and attempts, I cannot seem to be able correct the problem. Basically, I have the following gems installed: geokit (1.6.0, 1.5.0) geokit-rails31 (0.1.3) and have the following in my model class House < ActiveRecord::Base acts_as_mappable end and Gemfile: gem 'geokit', '>= 1.5.0' gem 'geokit-rails31' I get the error with or without doing the following in my local app.

Passing instance variable to stylesheet assets

…衆ロ難τιáo~ 提交于 2019-12-31 01:10:35
问题 How do I pass an instance variable from my controller to my assets stylesheet? Can I do something like this preview_controller.rb def show @design = Design.first end and my assets file is preview.css.scss.erb body{ background-image: url('<%= @design.image_url.to_s %>'); } 回答1: You can't do this (the assets are pre-compiled and do no have access to variables from the request). You could have this in your HTML page itself: <head> <%= stylesheet_link_tag "application" %> <style> body{ background

How can i join with a derived table?

一曲冷凌霜 提交于 2019-12-31 00:49:09
问题 The sql statement is like this: select posts.id, posts.title from posts inner join (select distinct post_id,created_at from comments order by created_at DESC limit 5 ) as foo on posts.id=foo.post_id order by foo.created_at DESC; I want to get a rails 3 sql statement equivalent to the above one. What i tried is given below: The following sql query gives similar result. select distinct post_id, created_at from comments order by created_at DESC limit 5 @temp = Comment.select('distinct(comments

Mixed file types with CarrierWave

不想你离开。 提交于 2019-12-30 18:07:06
问题 I've a CarrierWave uploader that shall accept a variety of file types. Some are image types (e.g. jpg, png) others are not. I would like to create a medium version of the uploaded file with version :medium do process :resize_to_fit => [300, 300] end As this only works for image files, how can I distinguish between images and other types and omit the resizing for non-image files? At the moment CarrierWave tries to process the file regardless of it's type which leads to a MiniMagick processing

Mixed file types with CarrierWave

人走茶凉 提交于 2019-12-30 18:06:09
问题 I've a CarrierWave uploader that shall accept a variety of file types. Some are image types (e.g. jpg, png) others are not. I would like to create a medium version of the uploaded file with version :medium do process :resize_to_fit => [300, 300] end As this only works for image files, how can I distinguish between images and other types and omit the resizing for non-image files? At the moment CarrierWave tries to process the file regardless of it's type which leads to a MiniMagick processing

omniauth OAuthException & OAuth::Unauthorized

痴心易碎 提交于 2019-12-30 04:37:21
问题 I have installed omniauth 1.0. Also I have oauth-0.4.5, oauth2-0.5.1, omniauth-facebook-1.0.0, omniauth-twitter-0.0.6. omniauth.rb Rails.application.config.middleware.use OmniAuth::Builder do provider :developer unless Rails.env.production? provider :facebook, ENV['167257285348131'], ENV['c8c722f697scb2afcf1600286c6212a9'], :scope => 'email,offline_access,read_stream', :display => 'popup' provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI'] end

Create migration files in rails from existing mysql table

橙三吉。 提交于 2019-12-30 03:13:06
问题 I m developing an application in rails. I have created a table say "student" in mysql. Is there anyway to create its migration file in rails application? I have specified databse name in config/database.yml" and using others table too. But i want to create tables migration file. How can i do it? 回答1: Start by referencing your existing MySQL database in database.yml run rake db:schema:dump to generate the schema.rb file Paste the create_table methods from your schema.rb into a new migration,

redirecting from http://example.com to https://example.mysite.com

核能气质少年 提交于 2019-12-30 02:36:04
问题 This question has been asked in various permutations, but I haven't found the right combination that answers my particular question. The configuration Rails 3.1 (allowing me to use force_ssl in my ApplicationController ) Hosted on Heroku Cedar (so I can't touch the middleware) My SSL certs are registered for secure.example.com I've already added force_ssl to my ApplicationController, like this: # file: controllers/application_controller.rb class ApplicationController < ActionController::Base