English 中文(简体)
我的建筑方法已不再在铁路的废墟中工作。
原标题:My build method is no longer working in ruby on rails

在我网站的用户简介科花了几天时间之后,我发现,建设——知名度并不奏效。

I don t know what is wrong,it doesn t make sense as it was working perfectly fine the other day. Now it doesn t create a row in the profiles table every time a new user is created.

这里,我的用户控制员制定了行动守则:

  def create
    @user = User.new(params[:user])   
    respond_to do |format|
      if @user.save 
        @user.build_profile.save #same as Profile.new(:user_id => @user.id)
        login @user
        UserMailer.join_confirmation(@user).deliver
        format.js   { render :js => "window.location =  #{root_path} " } 
     #   flash[:notice] = "Welcome!"
      else

        format.js   { render :form_errors }
      end
    end
  end

Users model:

class User < ActiveRecord::Base

  has_one :profile, :autosave => true
  accepts_nested_attributes_for :profile

  # Setter and getter methods
  attr_accessor :password # virtual password attribute


  # A list of white list of attributes accessible by users in forms
  attr_accessible :email, :username, :password, :password_confirmation

简介模式:

class Profile < ActiveRecord::Base

  belongs_to :user



 #  attr_accessor   :password
   attr_accessible :first_name, :last_name, :gender, :motd, :birthday, 
   :marital_status, :sexual_preference, :location, :country, :ethnicity, 
    :about_me, :height, :eye_colour, :body_type, :likes, :dislikes, :drugs,
    :alcohol, :cigarettes, :bad_habits, :food, :music, :television, :book,
    :animal, :place, :possession, :sport

孟加拉方法错误:

NameError (undefined local variable or method `build_profile  for #<UsersController:0x00000101d63510>):
  app/controllers/users_controller.rb:16:in `block in create 
  app/controllers/users_controller.rb:14:in `create 

这实际上是一种空想,因为它正在为此而努力,并且已经停止了。

I would really appreciate some help with this Kind regards

<>Update>

光谱错误:

Failures:

  1) UsersController JOIN  create  success should create a user
     Failure/Error: post :create, :user => @user
     NoMethodError:
       undefined method `ethnicity  for #<Profile:0x0000010367cab0>
     # ./app/controllers/users_controller.rb:16:in `block in create 
     # ./app/controllers/users_controller.rb:14:in `create 
     # ./spec/controllers/users_controller_spec.rb:96:in `block (5 levels) in <top (required)> 
     # ./spec/controllers/users_controller_spec.rb:95:in `block (4 levels) in <top (required)> 

Finished in 2.75 seconds
47 examples, 1 failure, 1 pending

Failed examples:

rspec ./spec/controllers/users_controller_spec.rb:94 # UsersController JOIN  create  success should create a user

Strange! 我做了检查,我的 d布和旁听的 list名单都存在这种特征,因此我很aff。

我投下并重新移民,但还没有uck。

最佳回答

添加:

:before_create :build_profile 

到了用户模式,这确实是trick。

问题回答

您需要在本例用户中,在括号内,在你直截了当的接通电话中增加内容。 请参看:api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签