Rails

Rails will_paginate custom route

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I use will_paginate with a custom route? I have the following in my routes: map.connect 'human-readable/:name', :controller => :tags, :action => 'show' but will_paginate uses url_for as far as I can tell, but I want to use 'human-readable' instead of url_for, but how? Edit When I click the paging link generated by will_paginate , it's using: "tags/show?name=Elektronikindustri&page=1" Instead of: "/human-readable/show?name=Elektronikindustri&page=1" I want will_paginate to use my custom route instead of the actual controller name 回答1:

Share session (cookies) between subdomains in Rails?

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an app setup where each user belongs to a company, and that company has a subdomain (I am using basecamp style subdomains). The problem that I am facing is that rails is creating multiple cookies (one for lvh.me and another for subdomain.lvh.me) which is causing quite a few breaks in my application(such as flash messages being persistent though out all requests once signed in). I have this in my /cofig/initilizers/session_store.rb file: AppName::Application.config.session_store :cookie_store, key: '_application_devise_session', domain

cannot load such file ― 1.9/bcrypt_ext (LoadError)

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Hey I get the following Error when i try to start the rails server Any ideas? At the moment no possible solution worked... By the way I run Windows 8... might be the problem at all :D C : /RailsInstaller/ Ruby1 . 9.3 / lib / ruby / gems / 1.9 . 1 / gems / activesupport - 3.2 . 11 / lib / active_support / dependencies . rb : 251 : in `require': cannot load such file -- 1.9/bcry pt_ext (LoadError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in ` block in

Trying to get selenium working in rails 3 - “WebMock::NetConnectNotAllowedError”

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use selenium for the first time in a rails 3 app. (I've used it before with rails 2). I'm in an rvm which of course has its own gemset. I first ran a task with capybara, without selenium: #./spec/requests/homepage_spec.rb require 'spec_helper' describe 'home page', :type => :request do it 'should welcome the user' do visit '/' page.should have_content('Buddy') end end This ran fine. I then added a ":js => true" option to the options for describe, which is supposed to make it run using selenium (as far as i know). And got this

Execute a sudo command in Ruby on Rails app

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to execute a command like this from a Ruby on Rails app: sudo service squid3 restart If i try it with this code: It don't work, in the console i see that linux asks the password. How can i pass a password with this command? Or other suggestions... 回答1: You can try the sudo -S flag if available on you system (check man): echo secretPasswd | sudo - S service squid3 restart This means that the password will be in clear so you can add the user which needs to perform the task to the sudoers (which creates another security

Rails :dependent => :destroy VS :dependent => :delete_all

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In rails guides it's described like this: Objects will be in addition destroyed if they’re associated with :dependent => :destroy , and deleted if they’re associated with :dependent => :delete_all Right, cool. But what's the difference between being destroyed and being deleted? I tried both and it seems to do the same thing. 回答1: The difference is with the callback. The :delete_all is made directly in your application and deletes by SQL : DELETE * FROM users where compagny_id = XXXX With the :destroy , there is an instantiation of all of

Rails 4 - Bootstrap date picker

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a rails 4 app which I use with bootstrap and simple form. I'm trying to follow this tutorial so that i can have a single click date picker instead of separate date, month and year fields. https://learningnewtricks.wordpress.com/2013/07/03/bootstrap-date-picker-on-rails-so-simple/ I have implemented all of the steps in this tutorial, but nothing changes in the date picker. I have: gemfile: gem 'bootstrap-datepicker-rails' application.js @import "bootstrap-sprockets"; @import "bootstrap"; //= require underscore //= require gmaps/google

Rails: update_attribute vs update_attributes

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Object.update_attribute(:only_one_field, "Some Value") Object.update_attributes(:field1 => "value", :field 2 => "value 2 ", :field3 => "value3") Both of these will update an object without having to explicitly tell AR to update. Rails API says: for update_attribute Updates a single attribute and saves the record without going through the normal validation procedure. This is especially useful for boolean flags on existing records. The regular update_attribute method in Base is replaced with this when the validations module is mixed in, which

Rails: How do I print the request parameters?

匿名 (未验证) 提交于 2019-12-03 01:28:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a Rails 3 application and I want to print in the view the request parameters. How do I do it? Edit: The purpose is to see what is being sent in a Form. 回答1: I would use debug(params) . That will give you a nicely formatted view of them. 回答2: If you wanted to print all of the parameters, the easiest way would be to use the inspect puts params . inspect or better, use the Rails logger Rails . logger . debug params . inspect In your html/ERB, you can use <%= params . inspect %> 回答3: Parameters are stored in the params hash. For

What is a “resource” in Rails?

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Dumb question but I have some lingering confusion of what, exactly, a "resource" is in Rails. The term is used everywhere but I get a funny feeling it might be being used rather loosely. It's referenced in the model, the controller and, quite literally, in routes.rb . Is it the specific route? For example, map.resources maps the 7 RESTful "resources". So an example of one resource would be the call to, say, the index action of a particular class's controller?!? Is it a reference to the whole page/object being retrieved? or perhaps, more