ruby-on-rails-3.1

How to post html form data to controller using ruby on rails 3.1

狂风中的少年 提交于 2019-12-04 21:52:13
I am using ruby on rails 3.1. And am trying to post html form data to controller for saving the record in database. But I am getting routing error like this 'No route matches [POST] first/save' .But when I tried to run this link in address bar like '127.0.0.1:3000/first/save' it is working fine. Can any one please tell me where am doing wrong. My routes are like: Rails.application.routes.draw do root 'first#hello' get 'first/save' end And my html form is like: <form accept-charset="UTF-8" method='post' action='/first/save'> <label for='S.No'>S.No</label> <input type="text" name="s_no"

How to convert this respond_to options to use Rails 3 version?

老子叫甜甜 提交于 2019-12-04 20:56:33
respond_to do |format| if @user.save format.js { render :nothing => true, :status => :ok, :location => @user } else format.js { render :json => @user.errors, :status => :unprocessable_entity } end end All options I've tried (like putting respond_to :js at the top of controller, etc) don't quite work the way as in this. Rails 3 Format: Use respond_to :json and respond_with (@user) respond_to :json # You can also add , :html, :xml etc. def create @user= User.new(params[:user]) #---For html flash #if @user.save # flash[:notice] = "Successfully created user." #end respond_with(@user) end # Also,

Sending mails automatically through action mailer Rails 3.1

女生的网名这么多〃 提交于 2019-12-04 19:37:53
I have to send weekly emails to all the user about the latest things happening. I am using ActionMailer to accomplish other mailing task however I have no clue how to automate the weekly emails. Update I found whenever gem which could be used to schedule cron jobs. I guess this could be used to send weekly emails which I intend to. Still looking how to make it work with ActionMailer will update once I find the solution Update 2 This is what I have done so far using whenever gem:- in schedule.rb every 1.minute do runner "User.weekly_update", :environment => 'development' end in users_mailer.rb

Mongoid and has_secure_password

梦想的初衷 提交于 2019-12-04 19:33:35
问题 I am trying to use rails 3.1 authentication using mongoid instead of active model class User include Mongoid::Document include ActiveModel::SecurePassword has_secure_password validates_presence_of :password, :on => :create attr_accessor :email, :password, :password_confirmation field :email, :type => String field :password_digest, :type => String end the problem is password_digest is not recognized by the bycrypt as in active model example http://railscasts.com/episodes/270-authentication-in

Rails - application design for 2 user types

风格不统一 提交于 2019-12-04 19:17:12
I am writing ruby on rails app, that will have 2 different types of users (let's say sellers and buyers). I was thinking about using single table inheritance, but ultimately I decided to crate 2 separate models (I believe it's better solution in my case). The problem is when I try to create private message model (both sellers and buyers can contact each other). Typically I would just generate model called message with 3 fields (from_user_id to_user_id and content). This will not work in my case, because there might be 2 users with the same id (1 seller and 1 buyer). I was thinking about using

Delayed_job (2.1.4) error: Job failed to load: instance of IO needed. Handler nil

我与影子孤独终老i 提交于 2019-12-04 19:03:45
I created a simplistic achievements system and wanted to introduce delayed_job (2.1.4) to take care of the processing. However, the handler column in the delayed_jobs table is always nil, which results in the last_error text: Job failed to load: instance of IO needed. Handler nil Here is my setup: Achievement Observer class AchievementObserver < ActiveRecord::Observer observe User, Comment, ... def after_create(record) # initiate delayed job to check conditions Delayed::Job.enqueue(TrophyJob.new(record.id, record.class.name)) end ... end Trophy Job class TrophyJob < Struct.new(:record_id,

How to do joins on subqueries in AREL within Rails

混江龙づ霸主 提交于 2019-12-04 18:28:24
问题 I have a simple model class User has_many :logs class Logs related in the usual way through the foreign key logs.user_id. I'm trying to do the following using Arel and according to the Arel doc it should work. u_t = Arel::Table::new :users l_t = Arel::Table::new :logs counts = l_t. group(l_t[:user_id]). project( l_t[:user_id].as("user_id"), l_t[:user_id].count.as("count_all") ) l_t.joins(counts).on(l_t[:id].eq(counts[:user_id])) When I do that I get the error TypeError: Cannot visit Arel:

Ruby/Rails 3.1: Given a URL string, remove path

拈花ヽ惹草 提交于 2019-12-04 18:27:25
问题 Given any valid HTTP/HTTPS string, I would like to parse/transform it such that the end result is exactly the root of the string. So given URLs: http://foo.example.com:8080/whatsit/foo.bar?x=y https://example.net/ I would like the results: http://foo.example.com:8080/ https://example.net/ I found the documentation for URI::Parser not super approachable. My initial, naïve solution would be a simple regex like: /\A(https?:\/\/[^\/]+\/)/ (That is: Match up to the first slash after the protocol.)

What is good way to limit the amount of comments shown to a user until they choose to view all?

丶灬走出姿态 提交于 2019-12-04 17:53:33
Currently I have an each loop in the template for where the comments are display. Say a user has 50 comments to a micropost they have posted. A long list showing 50 comments will be displayed. To save space on the page I've decided I'd like to limit comments shown to 2-3 per micropost. If a user wishes to view more they can click "view more" or "view all". I'm wondering how a server would cope if there were like 10,000 comments and a user clicked "view all" which is why I may choose to implement "view more" then have like 50 more comments shown" Anyway I'd like to know a good way to limit the

Disabling asset fingerprinting with asset_path for a single asset

喜夏-厌秋 提交于 2019-12-04 17:52:04
问题 I want to use the normal asset name, e.g. app.js when calling the asset_path helper in my views. In production, it uses the cache-busting name, e.g. app-f73cf13e6f100eda6681381e7d3ae9eb.js . Is there a way to get the normal name using asset_path ? 回答1: Figured it out, pretty simple actually. Just have to add digest: false to asset_path like so: asset_path('app.js', digest: false) 回答2: By default assets.digest is enable in production environment and is recommended for several reasons. However,