ruby-on-rails-3

Change format for date input in Rails 3?

半城伤御伤魂 提交于 2019-12-25 08:58:36
问题 I am using a text_field for date input in Rails 3 and would like the date to be formatted as mm/dd/yyyy . While I've found a few solutions for displaying the date in that way, I haven't run across a workable method for accepting that format as an input. The problem is that in the case of ambiguous dates like "09/05/2011" , Rails interprets it as "May 9th" rather than "September 5th." What is the best way to get Rails 3 to interpret those sorts of inputs according to the mm/dd/yyyy format? 回答1

Rails 3 - How can you sort an AR query result by doing math on attributes?

為{幸葍}努か 提交于 2019-12-25 08:58:32
问题 I'm building a controller/view that provides a wide selection of player rankings (e.g. "Top 10 Leader Boards".) Using this model: class Player < ActiveRecord::Base attr_accessible :name, :games_played, :games_lost, :games_won, games_exited, :total_kills, :total_deaths, :total_points, :total_coins end In my controller I have some obvious query results to pass to my view to populate player ranking lists: @top_winners = Player.order("games_won DESC").limit(10) @top_assassins = Player.order(

Rails 3 - logging in a user automatically after creating the account

会有一股神秘感。 提交于 2019-12-25 08:57:49
问题 In my users_controller I have two methods signup_process and login . I would like to call login automatically for a user after a successful signup_process call. Is this possible? In other language frameworks I would usually just call the login controller action direct from the signup_process action passing the username and password - but I think that is frowned upon in Rails. Is there some way instead to post the user data to the users.login action from my controller? This must be a common

Rendering Haml file in a javascript response with rails

那年仲夏 提交于 2019-12-25 08:49:22
问题 I am trying to render a haml file in a javascript response like so: $('#<%= @email.unique_name %> .preview .mail_content').html('<%=j render( :file => "user_mailer/#{@email.key}") %>'); An example of the file that would render is: - variables = { :contact_first_name => @contact.first_name, :user_full_name => @user.name, :user_first_name => @user.first_name } = @email.intro_html(variables) %p= "Please click the link below to go directly to the results of #{@user.first_name}'s assessment. You

Rails 3.2.8. Upgrade checkboxes from Rails 1.x.x to 3.2.8

痞子三分冷 提交于 2019-12-25 08:43:48
问题 Just was checking this episode by Ryan Bates and it seems that Rails 3.2.x has different setup. Seems that check_box_tag requires different attributes other than Ryan puts in there. AS it writes back unexpected kEND... to <%= check_box_tag "task_ids[]", task.id %> Any help appreciated 回答1: Your error is unrelated to your use of check_box_tag . " unexpected kEND " indicates an unexpected end-of-file, meaning you've opened a block or other nested structure somewhere and failed to close it.

How to generate unique urls to track user signups?

久未见 提交于 2019-12-25 08:39:54
问题 I want to generate a unique url for each user that signs up for my app. The urls should all lead to the same sign up page but each one will be associated with the one user that received it when signing up. Then every time a new user signs up through the unique url, the number of signups associated with that url will increment by one. Therefore, I can track the number of signups generated by each user. How do I build such a system? This is for a Ruby on Rails app. 回答1: i am not exactly sure

How can I display all tags from all users for a model instance?

▼魔方 西西 提交于 2019-12-25 08:39:38
问题 I want to get all the tags from all the users in my app for a brand whose ID is 37. The following works but only gets the tags from one of the 2 users currently in the app: <%= BrandUser.last.brand.tags.join(", ") %> The following is my attempt but doesn't work: <%= BrandUser.where(:brand_id => 37).each {|brand| p brand.tags} %> Brand has_many tags, has_many brand_users and has_many users through brand_users User has_many :brand_users and has_many :brands, :through => :brand_users BrandUser

Rails 3 Override Destroy without Canceling callbacks, and triggering a ROLLBACK

佐手、 提交于 2019-12-25 08:35:41
问题 My desired behavior is that when destroy is called on an instance, that instance will not actually be destroyed, but it will just be marked as having been destroyed. This needs to percolate up for any model associations. In the models that I don't want to actually destroy, but just mark them as deleted I have a deactivated field. From what I can tell the < v3.0.0 way of doing this was to override destroy_without_callbacks (That's the way ActsAsParanoid does it), however that method no longer

Why delete method gives me wrong path? with

左心房为你撑大大i 提交于 2019-12-25 08:27:34
问题 I have simple delete link: = link_to "Delete", messages_path(message.id), :method => :delete Gives me error: No route matches [DELETE] "/messages.316" How to fix this? I have ruby 1.9.3p0 Rails 3.1.1 My routes.rb resources :messages do collection do get :outbox end end when i change this to message_path i recieve wrong number of arguments (0 for 1) -> full_trace: https://gist.github.com/1967988 -> all files: https://gist.github.com/1967994 outbox_messages GET /messages/outbox(.:format) {

whenever + delayed_job with cron job in starting worker

烂漫一生 提交于 2019-12-25 08:16:22
问题 I am learning cron job and delayed job, and I want to send emails using background job; for that I'm using the delayed_job gem. I don't want to start the worker manually by running the rake jobs:work command, but I want to set this rake in cron job so whenever an user login into the dashboard this command is fired and a mail is sent to his address. Following is my code: Sending mail method def dashboard @user = User.find(params[:id]) UserMailer.delay.initial_email(@user) end UserMailer def