Search Results

Search found 6 results on 1 pages for 'railsnew'.

Page 1/1 | 1 

  • how to update a record without worrying about primary key

    - by railsnew
    In ActiveRecord how can we update a record without worrying/knowing primary key. If I do Address.update(15, :user_name => 'Samuel') it corresponds to UPDATE addresses set user_name = 'Samuel' where id = 15 but what if i want to do: UPDATE addresses set user_name = 'Samuel' where cid = 15 what will be the ActiveRecord equivalent of that?? I tried: Address.update({:cid => 15}, :user_name => 'Samuel') but that does not work.

    Read the article

  • time difference on heroku server

    - by railsnew
    There seems to be a time difference on heroku server. >> Customer.last.id => 584 >> Customer.last.created_at => Thu, 06 May 2010 01:43:20 UTC +00:00 >> Time.zone => #<ActiveSupport::TimeZone:0x2b1dec47e5c0 @utc_offset=0, @tzinfo=#<TZInfo::DataTimezone: Etc/UTC>, @name="UTC"> >> Time.now => Wed May 05 19:05:15 -0700 2010 >> Time.now.zone => "PDT" Notice that current time is May 05 19...however, created_at date for last record is May 06 01:43. This does not make any sense. What can be causing this and how would I go about fixing this?

    Read the article

  • need help fixing unique key in rails. rails is adding id causing duplicate key

    - by railsnew
    I need some help in fixing the below issue. I had transaction blocks in my rails code like below: @sqlcontact = "INSERT INTO contacts (id,\"cid\", \"hphone\", mphone, provider, cemail, email, sms , mail, phone) VALUES ('"+@id1+"','" + @id1 + "', '"+ params[:hphone] + "', '"+params[:mphone]+ "', '" + params[:provider] + "', '" + params[:cemail]+ "', '" + @varemail+ "', '"+@varsms+ "', '"+ @varmail+"', '"+@varphone+"')" my app was deployed to heroku so I was advised by them to remove transaction blocks. So I changed the above to: @cont = Contact.new(:id => @id1, :cid => @id1, :hphone => params[:hphone], :mphone => params[:mphone], :provider => params[:provider], :cemail => params[:cemail], :email => @varemail, :sms => @varsms, :mail => @varmail, :phone => @varphone) @cont.save My app also already had data stored. Now the problem is that when I try to save a record ...I keep getting the error: duplicate key value violates unique constraint "contacts_pkey" The error also shows the sql query trying to insert data ...however, in that sql query i Do not see id value. As you can see from my code that I am passing the id. then why is rails not accepting it? does it always include its own sequential id? can I not overwrite the default rails magic? and if it does that...does it not look at data that is already in the DB?? I am really stuck here. What should I do? should I just go back to my transaction block

    Read the article

  • rails migration. modify starting point for auto_increment

    - by railsnew
    I have a table already created. I am looking for a rails migration where I can modify the starting point of the auto_increment number for id column of my table. Let's say I want it to start from 1000. I googled a bit and came across this: it says: :options "string" pass raw options to your underlying database, e.g. auto_increment = 10000. Note that passing options will cause you to lose the default ENGINE=InnoDB statement Can this be used for something I want? and how will the migration look since i am changing the column and not creating new one...

    Read the article

  • how to get id of the saved record in rails

    - by railsnew
    I am doing this from the console but i'd like to do this in my code too. Basically I am trying to add a record to the table and then get the id back. >> @record = Physician.create(:pname => "someone2") => #<Physician id: nil, pname: "someone2", pgroup: nil, created_at: nil, updated_at: nil, userid: nil, storeid: nil, licexpdate: nil, address: nil> >> @record.save => false >>

    Read the article

  • How to get id of the saved record in Ruby on Rails

    - by railsnew
    I am doing this from the console but I'd like to do this in my code too. Basically I am trying to add a record to the table and then get the id back. >> @record = Physician.create(:pname => "someone2") => #<Physician id: nil, pname: "someone2", pgroup: nil, created_at: nil, updated_at: nil, userid: nil, storeid: nil, licexpdate: nil, address: nil> >> @record.save => false >>

    Read the article

1