ruby-on-rails-3

Ordering by a two fields, one being created_at, In Rails

守給你的承諾、 提交于 2019-12-25 01:44:45
问题 This is a follow-up question to Custom, Efficient, Complex Ordering in Rails 3 I'd like to develop an efficient ordering method for a rails model I have. Suppose that I save a rating for all objects in a field named "popularity". If I wanted to sort by this rating I would do: Model.order('popularity ASC') How would I order by a skew for created at? Is there a way to, perhaps, convert the creation timestamp to an integer value, and then sort by popularity - created_at such that older objects'

Rails 3 Custom FormBuilder Parameters

会有一股神秘感。 提交于 2019-12-25 01:44:45
问题 I create a custom FormBuilder for my application, but I dont understand why I need to pass tow parameters as follow: f.text_field :my_model, :my_field Here is my builder: class AceBuilder < ActionView::Helpers::FormBuilder %w[text_field password_field text_area].each do |method_name| define_method(method_name) do |object_name, method, *args| options = args.extract_options! @template.content_tag(:div, :class => "control-group #{@object.errors[method].length > 0 ? 'error' : ''}") do @template

Why does devise me redirect me to /users instead of /users/edit when my account update fails?

前提是你 提交于 2019-12-25 01:44:21
问题 The problem is like this: If I use the default registration controller I get redirected: /users/edit to root when user update succeeds /users/edit to /users when update fails Because the default controller update action looks like this: if resource_updated sign_in resource_name, resource, bypass: true respond_with resource, location: after_update_path_for(resource) else clean_up_passwords resource respond_with resource end after_update_path_for is set by default to root If update fails I get

How implement the Back Link to the page from which comes from

天大地大妈咪最大 提交于 2019-12-25 01:43:06
问题 I have an application with associations and will pagination the pages. The index page from the main object "cat_list" shows links to the association "data_lists". The index page has also pagination with "will_paginate" I show for example page=3 "/cat_lists?page=3" I click the link of a "data_lists" for example "/cat_lists/8984/data_lists" This index page shows a list of data_lists with Edit, Destroy and a New link. And a Back Link to the cat_lists index page now "/cat_lists" What is the best

ActiveRecord::AssociationTypeMismatch (dynamic image uploader)

喜欢而已 提交于 2019-12-25 01:39:10
问题 I am trying to follow the tutorial Dynamic multiple image uploads with Ruby on Rails that creates a new model for photos and will associate them with another model. After copying and pasting all the code I'm getting an "AssociationTypeMismatch" error as follows. ActiveRecord::AssociationTypeMismatch in AdminForksController#update Photo(#2176152540) expected, got Array(#2148417160) app/controllers/admin_forks_controller.rb:23:in `update' { "commit"=>"update", "fork"=>{"position"=>"", "name"=>

Problems with routes.rb

只谈情不闲聊 提交于 2019-12-25 01:36:47
问题 I have a problem with routes.rb In my web application i have two pages with the login form "/home/index" and "/users/index" This is my routes file controller :home do get 'login' => :index post 'login' => :create end controller :users do get 'login' => :index post 'login' => :post_login end get "home/index" get "home/create" get "home/show" get "private/index" get "users/index" get "users/get_login" get "users/post_login" resources :users do collection do get 'get_login' post 'post_login' end

Can't render layout in rails 3

試著忘記壹切 提交于 2019-12-25 01:26:01
问题 I have an application which was written for rails 2. I'm upgrading to rails 3. Most of the functionality of my app works but it does not render any layout. I'm using default 'erb' engine. I've explicitly called a layout in my controller but it just does not render even the simplest layout layout 'application' It does not throw any error. When I create a new project and try to render a layout in it, it works perfectly. 回答1: You have to use render :layout => 'application' You can check it out

Rails 3 Authlogic problem with single access token and logout on timeout

核能气质少年 提交于 2019-12-25 01:24:27
问题 I'm having a problem using an authlogic single access token to access a page when logout on timeout is set to true and a timeout is set. user.rb: acts_as_authentic do |c| c.logged_in_timeout = 15.minutes end user_session.rb: logout_on_timeout true controller: def single_access_allowed? ["download_xml"].include?(action_name) end If I try to access a page/method using the token it redirects straight away to my login page. The logout on timeout works when its turned on. If i remove the timeout

Rails 3: Different namespace inside nested resource?

时间秒杀一切 提交于 2019-12-25 01:14:57
问题 Is there a way to use a (different) namespaces inside nested resources? For example, I have: resources :users do resources :tags end and I'd like to place the tags controller inside controllers/common, while placing users controller inside controllers/user, with the equivalent for templates. If I try this: namespace :user do resources :users do namespace :common do resources :tags end end end I'll get redundant route names: user_common_tags , etc. But I want something like common_tags 回答1:

How can I map data from associations in “Edit” Forms in Rails?

烂漫一生 提交于 2019-12-25 01:12:01
问题 This is a follow-up to How to I serve data from an object's associations in rails forms? I am wondering, I would like to use eager loading to serve to an edit page of an Article object the tags (as well as other attributes that are saved through associated tables. In the previous question, I was informed that I could use eager loading of associations to pre-load that data. IE in the controller I augment the .find call to include @article = Article.find(params[:id], :include => [:tags]) This