ruby-on-rails-3

How to validate a single attribute for a submitting ActiveRecord instead of all its attributes?

本小妞迷上赌 提交于 2020-02-05 04:33:15
问题 I am using Ruby on Rails 3 and I would like to validate a single attribute for a submitting ActiveRecord instead of all its attributes. For example, in my model I have: validates :firstname, :presence => true, ... validates :lastname, :presence => true, ... I would like to run validation on the :firstname and on the :lastname separately . Is it possible? If so, how can I make that? P.S.: I know that for validation purposes there are methods like "validates_presence_of", "validates

Rails how to Gzip Javascript? (Heroku)

混江龙づ霸主 提交于 2020-02-04 07:34:25
问题 I have run google page speed and it is saying that I should Gzip my javascript files? How do I gzip my javascript files? My website is hosted on heroku if that mattter 回答1: This answer is out of date but I can't delete it because it was accepted. So I'm turning it into a community wiki so that people can fix it up. Heroku should be gzipping everything automatically (as long as the client supports it of course). From an old blog post: All apps deployed to Heroku automatically compress pages

Rest-Client get authenticity_token to create new record

≯℡__Kan透↙ 提交于 2020-02-02 15:22:23
问题 I try to create an new person out of an ruby program, for this task i use rest-client: require 'rest_client' require 'nokogiri' page = Nokogiri::HTML(RestClient.get("localhost:3000/people/new")) token = page.css("input[name='authenticity_token']") token2 = token[0]["value"] RestClient.post 'localhost:3000/people', :authenticity_token => token2, :person => {:name => 'Joseph'}, :commit => 'Create Person' I tried to get an authenticity_token by first make an get request to people/new and read

problems showing only projects that belong to a user

♀尐吖头ヾ 提交于 2020-02-02 13:33:12
问题 So I am building a rails app where you can display projects and so on and so forth. I have the following code in my projects controller: def create @project = Project.create(params[:project].merge(:user_id => current_user.id)) if @project.save redirect_to project_path(@project), :flash => {:success => 'We have created your project'} else redirect_to :back, :flash => {:error => 'Cannot allow an empty project name'} end end this will create a project, from what I understand based on and related

problems showing only projects that belong to a user

♀尐吖头ヾ 提交于 2020-02-02 13:33:07
问题 So I am building a rails app where you can display projects and so on and so forth. I have the following code in my projects controller: def create @project = Project.create(params[:project].merge(:user_id => current_user.id)) if @project.save redirect_to project_path(@project), :flash => {:success => 'We have created your project'} else redirect_to :back, :flash => {:error => 'Cannot allow an empty project name'} end end this will create a project, from what I understand based on and related

problems showing only projects that belong to a user

99封情书 提交于 2020-02-02 13:32:11
问题 So I am building a rails app where you can display projects and so on and so forth. I have the following code in my projects controller: def create @project = Project.create(params[:project].merge(:user_id => current_user.id)) if @project.save redirect_to project_path(@project), :flash => {:success => 'We have created your project'} else redirect_to :back, :flash => {:error => 'Cannot allow an empty project name'} end end this will create a project, from what I understand based on and related

Rails send_file multiple styles from Paperclip, how can I avoid code repetition?

僤鯓⒐⒋嵵緔 提交于 2020-02-02 13:30:17
问题 This is the default code I'm using in an associated model to download images from Paperclip as a save_to. months_controller def download @wallpaper = Wallpaper.find(params[:wallpaper_id]) @month = @wallpaper.months.find(params[:id]) send_file @month.wallpaper_picture.path, :filename => @month.wallpaper_picture_file_name, :type => @month.wallpaper_picture_content_type, :disposition => 'attachment' end routes resources :wallpapers do resources :months end match 'wallpaper/:wallpaper_id/download

Internal messaging in Rails

白昼怎懂夜的黑 提交于 2020-02-01 09:48:47
问题 I'm using this tutorial to get internal messages working on my site: http://www.novawave.net/public/rails_messaging_tutorial.html But, since my latest upgrade to Rails 3, I'm getting this error: NoMethodError in MsgController#sendmsg undefined method `each' for #<String:0xcc8acc0> Application trace: app/models/message.rb:16:in `prepare_copies' app/controllers/msg_controller.rb:140:in `sendmsg' The Message model: class Message < ActiveRecord::Base belongs_to :author, :class_name => "User" has

How to reuse scenarios within different features with rspec + capybara

荒凉一梦 提交于 2020-02-01 03:42:24
问题 Say I have some scenarios that I want to test under different contexts, or "features". For example, I have scenarios which involve the user visiting certain pages and expecting certain ajax results. But, under different conditions, or "features", I need to perform different "background" tasks which change the state of the app. In this case I need to run the same scenarios over and over again to make sure that everything works with the different changes to the state of the app. Is there a way

Why does my rails command always create a new application?

跟風遠走 提交于 2020-02-01 00:34:01
问题 Forgive me as I'm new to both *nix and ruby on rails. My rails command always creates a new application and I can't figure out why. Running "rails new myApp" will just generate a new rails application named "new" in the current directory. Likewise "rails server" just creates a new application in a folder named "server". Any ideas? I'm using Ubuntu 11.04 and rails 3.0.9. 回答1: When you create your application with rails new myApp , there should be a myApp/script directory and in there will be a