I have a typical rails form with form_for(@user...blah blah) There is a field to enter the email address: email. But that same email address has to be entered into the invitation_last_sent_to. So the same value, in two different columns. There is no problem when saving in the column ''email'' but I want to save that same email value into invitation_last_sent_to column in the controller. I have tried the following in users_controller.rb and when I get the rails console, the value in invitation_last_sent_to is always nil. @user.invitation_last_sent_to = @user.email @user.invitation_last_sent_to = params[:user][:email] @user.invitation_last_sent_to = params[:email] Please help. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 August 2011 20:21, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a typical rails form with form_for(@user...blah blah) > > There is a field to enter the email address: email. But that same email > address has to be entered into the invitation_last_sent_to. So the same > value, in two different columns. > > There is no problem when saving in the column ''email'' but I want to save > that same email value into invitation_last_sent_to column in the > controller. > > I have tried the following in users_controller.rb and when I get the > rails console, the value in invitation_last_sent_to is always nil. > > @user.invitation_last_sent_to = @user.email > @user.invitation_last_sent_to = params[:user][:email] > @user.invitation_last_sent_to = params[:email]Use ruby-debug to break into your code here and inspect the data and see what is going on. See the Rails Guide on debugging for how to do this. I presume, though, that you are doing the above in the create action before the save, or in the update action before update_attributes. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''m doing it in the create action. I did use debug to inspect @user and params and that''s why I used... @user.invitation_last_sent_to = @user.email @user.invitation_last_sent_to = params[:user][:email] @user.invitation_last_sent_to = params[:email] ...but none of those 3 seem to work. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 August 2011 20:53, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m doing it in the create action. I did use debug to inspect @user and > params and that''s why I used... > > @user.invitation_last_sent_to = @user.email > @user.invitation_last_sent_to = params[:user][:email] > @user.invitation_last_sent_to = params[:email] > > ...but none of those 3 seem to work.so in the debugger what was the value of @user.email after @user = User.new(params[:user]) and what was the value of @user.invitation_last_sent_to after @user.invitation_last_sent_to = @user.email If you don''t understand what you see in the debugger copy the output from the terminal showing the above tests and paste here along with the code for the create action. Colin> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Is it maybe because it''s a nested resource? I have this in users_controller.rb ----------------------------------------- @user = @company.users.build(params[:user]) @user.invitation_last_sent_at = Time.now @user.invitation_last_sent_to = ??????? ------------------------------------------------------ I just tried @company.users[0].email and it also doesn''t work. -------------------------------------------------------------------- Started POST "/companies/45/users" for 127.0.0.1 at Thu Aug 11 15:37:28 -0500 2011 Processing by UsersController#create as HTML Parameters: {"commit"=>"Add this person", "authenticity_token"=>"2sp49Lxt9a533aBCwdmiCAOmDSyfkO83dHpGI5JRFEE=", "utf8"=>"✓", "company_id"=>"45", "user"=>{"title"=>"", "last_name"=>"Mini-Me", "first_name"=>"Leo", "email"=>"someemail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"}} ----------------------------------------------------------------- -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Leonel *.* wrote in post #1016258:> Is it maybe because it''s a nested resource? >Possibly. This certainly works: class PagesController < ApplicationController def home @title = "Home" end end == Test2App::Application.routes.draw do resources :users root :to => "pages#home" == class UsersController < ApplicationController def new @user = User.new @title = "Sign up" end def create @user = User.new(params[:user]) @user.last_sent_to = @user.email if @user.save @title = "Home" render ''pages/home'' else @title = "Sign up" render ''new'' end end def show end end == <h1>Pages#home</h1> <p>Find me in app/views/pages/home.html.erb</p> <%= link_to "New user form", new_user_path %> == <h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> <%= form_for(@user) do |f| %> <div><%= f.label :email %></div> <div><%= f.text_field :email %></div> <div><%= f.submit "Submit" %></div> <% end %> == <!DOCTYPE html> <html> <head> <title><%= @title %></title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html> == <h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> <%= form_for(@user) do |f| %> <div><%= f.label :email %></div> <div><%= f.text_field :email %></div> <div><%= f.submit "Submit" %></div> <% end %> == http://localhost:3000 => home page click link on home page => new.html.erb fill in form and click submit => data for both :email and :last_sent_to appears in database for data -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 August 2011 21:44, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Is it maybe because it''s a nested resource? > > I have this in users_controller.rb > ----------------------------------------- > @user = @company.users.build(params[:user]) > @user.invitation_last_sent_at = Time.now > @user.invitation_last_sent_to = ???????What? You have that line if the controller?> ------------------------------------------------------ > > I just tried @company.users[0].email and it also doesn''t work.What do you mean it doesn''t work? You need to give more information not vague comments. Show us the results of what you are doing in the console by copying and pasting the console output here. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>> I have this in users_controller.rb >> ----------------------------------------- >> @user = @company.users.build(params[:user]) >> @user.invitation_last_sent_at = Time.now >> @user.invitation_last_sent_to = ??????? > > What? You have that line if the controller?No, I meant I tried those 3 different lines in different times. Here''s the create method in the users_controller.rb ------------------------------------------- def create @company = Company.find(params[:company_id]) @user = @company.users.build(params[:user]) @user.user_state = "invited" @user.invitation_last_sent_at = Time.now @user.invitation_last_sent_to = @user.email respond_to do |format| if @user.save Notifier.user_invited(@user).deliver format.html { redirect_to(users_url, :notice => user_long_name) } format.xml { render :xml => @user, :status => :created, :location => @company } else format.html { render :action => "new" } format.xml { render :xml => @company.errors, :status => :unprocessable_entity } end end end --------------------------- I did find I was getting a "mass-assign" error in the server log, so I added the attribute to attr_accesssible in user.rb ---------------------------------- attr_accessible :email, :first_name, :last_name, :invitation_last_sent_at [... more attributes ...] ----------------------------------- the mass-assign error went away but invitation_last_sent_to it''s still nil. I already tried in the console. ------------------------------------ irb(main):001:0> u = User.new => #<User id: nil, email: nil, password_hash: nil, password_salt: nil, created_at: nil, updated_at: nil, company_id: nil, first_name: nil, last_name: nil, title: nil, username: nil, user_state: nil, confirmation_token: nil, confirmed_at: nil, auth_token: nil, role_id: nil, invitation_last_sent_at: nil, invitation_last_sent_to: nil> irb(main):002:0> u.email = "somemail-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" => "somemail-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" irb(main):003:0> u.invitation_last_sent_to = u.email => "somemail-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" ---------------------------------------------------------- So it''s working in the CONSOLE but not in the APP. I''m sure there is something else in my code that it''s making it nil, will keep on looking. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 August 2011 16:55, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>>> I have this in users_controller.rb >>> ----------------------------------------- >>> @user = @company.users.build(params[:user]) >>> @user.invitation_last_sent_at = Time.now >>> @user.invitation_last_sent_to = ??????? >> >> What? You have that line if the controller? > > No, I meant I tried those 3 different lines in different times. Here''s > the create method in the users_controller.rb > ------------------------------------------- > def create > @company = Company.find(params[:company_id]) > @user = @company.users.build(params[:user]) > -tENV8f5wrGRQFI55V6+gNQ@public.gmane.org_state = "invited" > -46v55a1WOL9Q1u4Ge+2UMQ@public.gmane.org_last_sent_at = Time.now > -46v55a1WOL9Q1u4Ge+2UMQ@public.gmane.org_last_sent_to = @user.emailBreak in here with the debugger and see what is happening.> > respond_to do |format| > if @user.save > Notifier.user_invited(@user).deliver > format.html { redirect_to(users_url, :notice => user_long_name) } > format.xml { render :xml => @user, :status => :created, :location > => @company }Presumably you are seeing the above happening, so showing that the save is working.> else > format.html { render :action => "new" } > format.xml { render :xml => @company.errors, :status => > :unprocessable_entity }and presumably the above is not happening. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.