ruby-on-rails-3.1

Confused about attr_accessor and attr_accessible in rails

允我心安 提交于 2019-12-11 16:27:01
问题 this is a simple signup application schema.rb create_table "users", :force => true do |t| t.string "email" t.string "password_hash" t.string "password_salt" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false User.rb attr_accessible :email, :password, :password_confirmation attr_accessor :password before_save :encrypt_password validates_confirmation_of :password validates_presence_of :password, :on => :create validates_presence_of :email validates_uniqueness_of

Removing Email Address Using Regex and Before_Save

家住魔仙堡 提交于 2019-12-11 15:39:35
问题 Trying to use a before_save in my Post model and then regex to replace anything that looks like an email with the word 'forbidden'. This is to cut down on spam from comments/posts created by users in a discussion board. It is currently giving me a syntax error; but I am sure it is more than that? How do I fix it? Post.rb before_save :remove_emails # Prevents and replaces any emails or URLs posted by user as <forbidden> def remove_emails self.post = post.gsub^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z

AbstractController::DoubleRenderError in Admin

为君一笑 提交于 2019-12-11 15:28:13
问题 I am working on spree commerce, I am trying to tweak couple of actions in the active_sale_controller. I have some conditions, if the condition fails I am redirecting_to (:back) else I am proceeding to next step. The problem I am facing right now is I have used redirected_to (:back), twice in the same action and also I have one more redirected_to to some other controller in the same action, the browser shows a error which is says "Render and/or redirect were called multiple times in this

in UsersController#create, User.new(params[:user]) return an empty User (params looks good)

删除回忆录丶 提交于 2019-12-11 15:25:42
问题 I'm kind of new to Rails 3.1. and I'm facing an issue only in my production env with my Signup form (actually, it's more about the controller). Here is the code in User class UsersController < ApplicationController [...] def create @user = User.new(params[:user]) logger.info "value of login in param : #{params[:user][:login]}" #-> log the actual login logger.info "value of login : #{@user.login}" #-> log empty @user.admin = false if @user.save flash[:notice] = t('flash.notice.user.create

Rails 3.1 load controller from different path based on subdomain

只谈情不闲聊 提交于 2019-12-11 14:24:42
问题 Is it possible to dynamically change the path from which controllers are used? Ryan Bates showed how to change the view_paths here: http://railscasts.com/episodes/269-template-inheritance I'm making a CMS where a user can create a site and enter their own subdomain. I'd like "/" to point to "public#welcome" if there's no subdomain, but if there is a subdomain, I want it to point to "sites/public#welcome". I'm using Rails 3.1 if that makes any difference. 回答1: You should be able to solve this

Rails Database Association / Migration

回眸只為那壹抹淺笑 提交于 2019-12-11 13:36:55
问题 I'm learning rails and I'm trying to figure out database associations. If I have a database table with say Users that has an id, name, email, etc. and a Message table with the message, a sender (User) and recipient (also a User), how do I set up the migration and the models. Here, I'm using Rails 3.1. I'm pretty sure I can do it with just one User in the Message table with the references:User in the migration, but I'm not sure how to set up two of them. 回答1: Some resources to get you started:

How to save 2 id in joint table for many-to-many relationship in rails 3.1

这一生的挚爱 提交于 2019-12-11 11:55:56
问题 There are two models. One is rfq and another one is standard. It is like: class Rfq << ActiveRecord::Base has_and_belongs_to_many :standards end class Standard << ActiveRecord::Base has_and_belongs_to_many :rfqs end Table rfqs_standards has been created. My question is when creating rfq, how to save the paid of rfq_id and standard_id in table rfqs_standards automatically. Thought adding accepts_nested_attributes_for :standard in rfq model. However since there is no real attributes (but just

How to display flash error without refreshing page?

梦想与她 提交于 2019-12-11 11:37:34
问题 I have a submit form that is shown in a lightbox. I validate the form pretty heavily but there are circumstances where a playlist is already submitted, in which case I can't tell before a form is submitted. Currently I have :disable_with => 'Submitting...' It would be completely awesome if the error was sent back to the form, and the submit button would re-enable. Would this be possible without too much complication? I also have a second related question... Because my form is in a lightbox,

Load only part of environment for rake task?

放肆的年华 提交于 2019-12-11 11:29:31
问题 I've seen a bunch of articles relating to loading the entire Rails environment for a task. However, I'm concerned that this is unnecessary because I only use two models for my task (plus the 'resque' and 'resque/scheduler'). How can I only load certain parts of an environment for my task? Also, this question seems to be the same, but it's gotten old and no one seems to have sufficiently answered it... I'll ask now, ahead of time, that someone please give code rather than just an explanation.

Why do I get “no route matches” for requests to the asset pipeline?

南楼画角 提交于 2019-12-11 10:35:20
问题 I'm working on upgrading an app to use Rails 3.1 and I'm trying to use the asset pipeline. As a test, I've added foobar.js to app/assets/javascripts . The Setup In application.rb , I've added config.assets.enabled = true . Going on this guide, I think that's all I have to do. Checking it out If I load the console and check Rails.application.config.assets.paths , I do see app/assets/javascripts in the load path. Also, if I check MyAppName::Application.assets , I get back a Sprockets: