Manny 777 | 1 Apr 01:00 2011

How to work with data from DB in controller

Hi there,
 I have the collection with items "name", "surname", "sequence". When
I'm saving next user to my collection, I need to get the highest value
of "sequence" in my collection, this value increment and save to new
user... but I don't know, how to get the highest value stored in
collection...

But obviously I'm getting error message about undefined local variable
sequence.

I am trying this problem to solve following:
--
high = Users.find(:order => 'sequence_at DESC', :limit => 1)

    unless high.sequence.nil? || high.sequence == 0
      save_seq += 1
    else
      save_seq = 1
    end

     <at> user_new = Users.new(:name => params[:name], :sequence => save_seq)

I will be very glad for every help!
Thanks, Manny

-- 
Posted via http://www.ruby-forum.com/.

--

-- 
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
(Continue reading)

Bryan Crossland | 1 Apr 01:40 2011
Picon

Re: Form method="post/get" and routes

On Thu, Mar 31, 2011 at 4:13 AM, Manny 777 <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:

Hello there,
 I'm doing a form and I want to send this form with method="post".  Head
of form looks so:

<%= form_tag({ :controller => 'admin', :action => 'menu_add' }, {
:method => 'post' }) do %>

And in controller I have this:

 def menu_add
   menu_new = Menu.new(...)
   ...
 end

And with I am fighting - I'm not using type of route get
'admin/menu_add' - I'm sending a form by method post -- but I am still
getting the route error "Unknown action - The action 'menu_add' could
not be found for AdminController" -- how it is possible, if I'm not
using route 'admin/menu_add' by get, but by post?

And one question yet - exist some effective way, how to work with
routes? If i want to add some new action, I must to add to file
'routes.rb' line as:

get 'admin/menu_add'
post 'admin/menu_add'

It's a bit boring to add every new action so manually... is some better
way, how to do?

Thanks a lot, Manny.

I'm not sure which version of Rails you are using so I've provided a link to a tutorial for both. I think if you read/watch them it will help to clear up a lot of the issues you are having.

Rails 2 routes
http://darynholmes.wordpress.com/2008/03/15/beginners-tutorial-routing-in-rails-20-with-rest-part-1-of-n/

Rails 3 routes
http://railscasts.com/episodes/203-routing-in-rails-3

Good luck.

B.

--
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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Perry Smith | 1 Apr 02:07 2011

Route with optional segments

In Rails 2.3.5, is this the proper way to do this?

  map.calls "calls/:group/:view/:subselect", :controller => 'calls',
:action => 'index'
  map.calls "calls/:group/:view",            :controller => 'calls',
:action => 'index'
  map.calls "calls/:group",                  :controller => 'calls',
:action => 'index'
  map.calls "calls",                         :controller => 'calls',
:action => 'index'

I want to accept

 /calls
 /calls/abc
 /calls/abc/def
 /calls/abc/def/ghi

where "group" would be assigned "abc" in cases 2-4, "view" would be
assigned "def" in cases 3 and 4, and subselect would be assigned "ghi"
in case 4.

I kept trying to do something like:

  /calls(/%group(/%view(/%subselect)?)?)?

but never got it to work.

Thank you,
pedz

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Bryan Crossland | 1 Apr 02:22 2011
Picon

Re: Re: ActiveRecord: when exactly is a record (model) saved to the database?

On Thu, Mar 31, 2011 at 9:06 AM, Alexey Muranov <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:

I am posting a related question in the same thread.
It is more of a philosophical question.
Can anybody please give me some philosophical explanation why the
following behavior of ActiveRecord is considered ok (or should i submit
a bug report/feature request?):

In console:
> p = Person.create(:name=>'Bill')
> p.destroy
> p.name   # => "Bill"
> p.save  # => true
Nothing is saved in the database, but what disturbs me more is that
"save" returned true in such case.


In this first example you are inializing an object instance of Person by calling the "create" method. The "create" method of class Person does a "create" to the database where as the method "new" does not. The "destroy" method you called sends a destroy to the database for the record based on that id but does not destroy the obect instance. This is because object is not a pointer to the database record, it's an instance of the class Person. This is why you can still retrieve the name from your object instance later by calling the method "name". The "save" method should be doing the action of create or update in the database (depending on if the "new" or "create" methods were called to inialize the object instance). It returning "true" is strange since the record in the database is neither being created or updated. That may indeed be a bug.

 
A more elaborate version:
> p = Person.create(:name=>'Bill')
> p.id  # => 1
> pp = Person.find(1)
> pp.destroyed
> p.persisted?  => true
> p.destroyed?  => false
> p.save  # => true
but the database is empty.
Again, what bothers me the most is the "true" returned by "save".


In this example you are inializing two seperate object instances of the class Person. One by calling the method "create" and the second by finding the first record in the database. Again, object instances are not pointers to the database record. The objects "p" and "pp" are totally seperate. Like above, activating the "destroy" method sends a destroy to the database based on the id in the object but does not destroy the calling object or any other object that happens to have the same id value. The "save" method returning true is strange since the record with the id value of 1 can't be created again or updated.

Someone else might know more as to why "save" returns true in this case. If not, then it is most likely a bug.

B.

--
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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alex Katebi | 1 Apr 02:38 2011
Picon

require files

How to I handle loading files with relative path?


For example:

  require '../spec_helper.rb' 

   require '/home/user/myapp/spec/spec_helper.rb'

Thanks!
Alex

--
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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tom Mac | 1 Apr 06:31 2011

Re: How to secure paypal signature, username and password stored in app_config

Hi
   I am using app_config.yml exactly like
http://railscasts.com/episodes/143-paypal-security
       Please help

Thanks

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Mallikarjun rao | 1 Apr 07:40 2011

Re: print for page

I referring to actually sending the page to the printer.

can you please send the process of that/.

On Tue, Mar 29, 2011 at 5:50 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:
Are you referring to actually sending the page to the printer, or generating a "printer friendly page"?

The answer is different depending on which you were referring.



--
Thank you
----------------
Mall!karjun


--
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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling | 1 Apr 07:45 2011
Picon

Re: How to work with data from DB in controller

On 1 April 2011 00:00, Manny 777 <lists@...> wrote:
> But obviously I'm getting error message about undefined local variable
> sequence.

Are you sure you're not getting "undefined local variable save_seq"?
Did you cut/paste the code here, or did you re-type it (so is it
*exactly* what's in your controller, or could there be small
differences?)

It could be worth you setting save_seq:
  high = Users.find(:order => 'sequence_at DESC', :limit => 1)
  save_seq = high.sequence
  unless high.sequence.nil? || high.sequence == 0
  ...etc

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Michael Pavling | 1 Apr 07:50 2011
Picon

Re: Re: ActiveRecord: when exactly is a record (model) saved to the database?

On 1 April 2011 01:22, Bryan Crossland <bacrossland@...> wrote:
> Someone else might know more as to why "save" returns true in this case. If
> not, then it is most likely a bug.

Try it in your SQL console of choice:

  UPDATE my_table SET field1 = 'new value' WHERE id = <non-existant-id-value>

You'll get a message "no records were updated" - that's a successful
execution as far as SQL is concerned.

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

uday kiran | 1 Apr 08:00 2011
Picon

integrate facebook



can u tell me  how to integrate facebook in ruby on rails application


please give me help

--
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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Gmane