ruby-on-rails-3.1

How do I associate a CoffeeScript file with a view?

帅比萌擦擦* 提交于 2019-12-17 18:18:50
问题 Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline By default all coffeescript is compiled into a single application.js file, this is a good thing. Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc... Many of these scripts will be specific to a

Rails 3.1 Load css in particular order

☆樱花仙子☆ 提交于 2019-12-17 17:49:06
问题 I see that in development environment in rails 3.1 the css are loaded in alphabetic order and not in the order I want. I want a particular css file to be at the end so it over-writes any styles given to the class before. How can we achieve that? 回答1: It is better to specify the order of each and every files manually: /* * This is a manifest file that'll automatically include all the stylesheets available in this directory * and any sub-directories. You're free to add application-wide styles

Find number of months between two Dates in Ruby on Rails

北战南征 提交于 2019-12-17 17:39:07
问题 I have two Ruby on Rails DateTime objects. How to find the number of months between them? (Keeping in mind they might belong to different years) 回答1: (date2.year * 12 + date2.month) - (date1.year * 12 + date1.month) more info at http://www.ruby-forum.com/topic/72120 回答2: A more accurate answer would consider days in the distance. For example, if you consider that the month-distance from 28/4/2000 and 1/5/2000 is 0 rather than 1 , then you can use: (date2.year - date1.year) * 12 + date2.month

Passing parameters from view to controller

怎甘沉沦 提交于 2019-12-17 16:19:42
问题 I got a bit of a newbie question. I'm trying to pass a variable from my view to my controller. Is there anyway my method in my controller can receive variables from my view? Post view: show.html.erb: .... <%=link_to "Add relationship", :method => :add_relationship(@rela) %> Controller: post.controller.rb: def add_relationship(rela) @post = Post.find(params[:id]) if current_user.id == @post.user_id @post.rel_current_id = rela.id @post.save redirect_to relationships_url else redirect_to posts

No route matches [GET] “/users/sign_out”

怎甘沉沦 提交于 2019-12-17 15:34:33
问题 Here is my actual error: No route matches [GET] "/members/sign_out" Since most people will use "users" I thought it would be more helpful to have that in the title. At any rate, I am essential unable to logout. I can successfully edit my member profile. I am using devise 1.4.2 and Rails 3.1.0.rc4. Also, I have generated two separate devise models - one called "members" and the other called "admins". I was able to register and log into both of them (simultaneously) by manually navigating to

Rails 3.1 limit user created objects

旧城冷巷雨未停 提交于 2019-12-17 10:29:56
问题 I would like to limit the number of model Objects a user can create. I've tried the below but it is not working. I understand some changes have happened in rails 3.1 and not sure how to accomplish this now. class User < ActiveRecord::Base has_many :things, :limit => 5, :dependent => :destroy # This doesn't work end class Things <ActiveRecord::Base belongs_to :user end 回答1: Try something like this: class User < ActiveRecord::Base has_many :things end class Things <ActiveRecord::Base belongs_to

How do I write a Rails 3.1 engine controller test in rspec?

房东的猫 提交于 2019-12-17 10:27:25
问题 I have written a Rails 3.1 engine with the namespace Posts. Hence, my controllers are found in app/controllers/posts/, my models in app/models/posts, etc. I can test the models just fine. The spec for one model looks like... module Posts describe Post do describe 'Associations' do it ... end ... and everything works fine. However, the specs for the controllers do not work. The Rails engine is mounted at /posts, yet the controller is Posts::PostController. Thus, the tests look for the

Access Asset Path from Rails Controller

亡梦爱人 提交于 2019-12-17 08:35:11
问题 I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't inside a controller. I could access directly using "#{Rails.root}/app/assets/javascripts/configuration.yml" but when deploying the filename gets the digest string appended. How can I get the same path from a controller? 回答1: ActionController::Base

Error when running rails app - ExecJS::RuntimeError

孤街醉人 提交于 2019-12-17 06:51:59
问题 I tried googling this and I haven't found an answer yet to my problem. I am trying to run a simple controller script through rails and it is giving me this error when I reach the page. ExecJS::RuntimeError in Say#hello Obviously Say is the controller and hello is the method. Further down the page I get more info about the error. dyld: unknown required load command 0x80000022 (in /Users/JoeMoe/Sites/demoRails/app/assets/javascripts/say.js.coffee) I have checked this file and there is nothing

rails - “WARNING: Can't verify CSRF token authenticity” for json devise requests

社会主义新天地 提交于 2019-12-17 04:41:10
问题 How can I retrieve the CSRF token to pass with a JSON request? I know that for security reasons Rails is checking the CSRF token on all the request types (including JSON/XML). I could put in my controller skip_before_filter :verify_authenticity_token , but I would lose the CRSF protection (not advisable :-) ). This similar (still not accepted) answer suggests to Retrieve the token with <%= form_authenticity_token %> The question is how? Do I need to do a first call to any of my pages to