Forum: Ruby on Rails basic 'find' question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-02 09:22
(Received via mailing list)
I am struggling to understand the methodology here...

I have a find.rhtml

<%= start_form_tag :action => 'list2', :first_name = client %>
  <%# render :partial => 'form' %>
  <p><label for="client_first_name">First name</label><br/>
  <%= text_field 'client', 'first_name'  %></p>

  <%= submit_tag 'Find' %>
<%= end_form_tag %>

Which I presume calls list2.rhtml which has...

<%
odd_or_even = 0
for client in @clients
  odd_or_even = 1 - odd_or_even
%>

then a table/row/cell definitions and then list the clients
<td><%=h (client.wholename) %>
<% end %>

and within my clients_controller.rb I have

  def list2
    @clients = Client.find(:first,
      :conditions => "first_name = 'Elliot'")
    @client_pages, @clients = paginate :clients, :per_page => 10
  end

but it lists ALL clients and not just 'Elliot'

but more to the point...I want only those matching the find which I see
is passed through by putting <% debug params %> in the list2.rhtml
page...

!map:HashWithIndifferentAccess
commit: Find
client: !map:HashWithIndifferentAccess
  first_name: Elliot
action: list2
controller: clients

How/where do I get list2.rhtml to only list those records that match my
'find'?

Craig
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-02 19:01
(Received via mailing list)
In your list2 action the first line finds the first customer with name
Elliot and stores it to @clients instance variable and the second line
overrides this variable with the first 10 records from the clients
table.

Kent.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-03 00:22
(Received via mailing list)
OK - makes sense...

so I changed...

On Thu, 2006-02-02 at 12:59 -0500, Kent Sibilev wrote:
> > I have a find.rhtml
> >
> > <%
> > odd_or_even = 0
> > for client in @clients
----
to  for clients in @myclients
----
> >     @clients = Client.find(:first,
----
to     @myclients = Client.find(:all,
----
> > !map:HashWithIndifferentAccess
> > commit: Find
> > client: !map:HashWithIndifferentAccess
> >   first_name: Elliot
> > action: list2
> > controller: clients
> >
> > How/where do I get list2.rhtml to only list those records that match my
> > 'find'?
----
and I am only getting the record(s) that match - that is great. Now all
I need to figure out - and I haven't been able to figure out...

if 'find.rhtml' sends...

<%= start_form_tag :action => 'list2', :first_name = client %>
  <%# render :partial => 'form' %>
    <p><label for="client_first_name">First name</label><br/>
    <%= text_field 'client', 'first_name'  %></p>
  <%= submit_tag 'Find' %>
<%= end_form_tag %>

and

in clients_controller.rb

def list2
  @myclients = Client.find(:all,
    :conditions => "first_name = 'Elliot'")
end

works (list2.rhtml only displays records that match)

what can I do to take the result from find.rhtml
  <% text_field 'client', 'first_name' %>

in clients_controller.rb

where everything I try generates an error...

def list2
  @myclients = Client.find(:all,
    :conditions => "first_name = #{first_name}")
end

 @myclients = Client.find(:all,
   :conditions = "first_name = first_name")
or
 @myclients = Client(:params[:client])
or
 @myclients = Client.find(:all,
   :conditions = "first_name = client[ :first_name ]")
or

??? what is proper form to do this?

Thanks

Craig
1b9da5824527b6f67e5305c9f6867fc7?d=identicon&s=25 Amr Malik (Guest)
on 2006-02-03 00:40
(Received via mailing list)
My advance apologies if this is duplication. The ruby-forum seems to be
down
and I posted it via google groups, but there seems to be a dealy. Below
is my
message originally posted to google groups.

--------------------- 8xX ---------------------

I have:
1 dedicated Debian barebones system, I've installed Rails,lighty etc.
etc.
(following Ezra's excellent setup doc)
5 IP's
3 domains (mytypo.com , myapp1.com, myapp2.com)

I want to host 3 rails based production sites off of the same dedicated
box.
such that the users don't have to worry about what
port they connect to (appears as 80 to them)

What is the recommended way of hosting 3 production rails sites with 3
different domain names (resolving to the same dedicated box) off of
lighty from a single dedicated box? I can do the DNS setup such that
all three domains will point to one of my IP's, I'm not so sure how I
would sort out the incoming requests to different Rails homes
(potentially 3 separate rails versions serving each app - Typo, app1,
app2)

I'm sure there is a way. I guess I'm looking for a pointer as to how I
should go about doing this. I'm trying NOT to do a virtualmin install
and then do N virtual server installs and then install rails for each
(kind of what the textdrive virtual accounts do) if I can do it more
simply.

Any hints or pointers will be greatly appreciated.

Thanks for your comments,

Amr




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
9b7647d55df4584d7031130915556040?d=identicon&s=25 Will Briggs (Guest)
on 2006-02-03 01:01
(Received via mailing list)
http://www.lighttpd.net/documentation/simple-vhost.html

Set up a lighttpd virtual host entry for each app you wish to serve;
lighttpd will check which URL was used to access the site and route
the requests appropriately; have all domain names point to the same IP
address on your box (unless you need to use different network
interfaces for each site but want to host from a central machine,
which is a different question).

-Will
6559f9b9607a89074ea5e238d31ffbc2?d=identicon&s=25 Kelly Dwight Felkins (Guest)
on 2006-02-03 01:07
(Received via mailing list)
I think this is staight forward, but I have to admit I haven't done
multiple
"virtual domains" on lighty yet. However, my config looks like multiple
"virtual domains" would be easy. Please take a look:

$HTTP["host"] =~ "(www\.)?mydomain\.com" {
        server.document-root  = "/var/www/mydomain/current/public"
        server.error-handler-404 = "/dispatch.fcgi"

        fastcgi.server              = ( ".fcgi" =>


I think you would simply duplicate this section for each domain.

I also used Ezra's setup, except that I used a debian lighty package. By
using this lighty package log_rotate and startup/shutdown were setup
"the
debian way". I hope this helps.

-Kelly
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-03 01:16
(Received via mailing list)
Amr-

	You have a few choices. You can either use lighttpd vhosts of sorts
with the config file I pasted below. Or since you have multiple IP's
you can bind each app to its own IP and use a single lighty instance
for each app. If you do it with vhosts, you will have to restart all
your apps to restart one of your apps. If you do it with a separate
lighty on each IP for each app, you can restart them individually.

-Ezra

################
server.port = 80
server.errorlog = "/var/www-light/lighttpd.error.log"
accesslog.filename = "/var/www-light/lighttpd.access.log"
server.username = "www-data"
server.groupname = "www-data"
server.dir-listing = "disable"
#server.event-handler = "linux-rtsig"

# default; this should never be used.
server.document-root = "/var/www-light/empty/"

server.indexfiles = (
         "dispatch.fcgi", "index.html", "index.htm"
)

server.modules = (
         "mod_access",
         "mod_status",
         "mod_rewrite",
         "mod_fastcgi",
         "mod_accesslog"
)

status.status-url = "/server-status"

url.access-deny = ( "~", ".inc", "#" )

$HTTP["host"] =~ "myapp1.com" {
server.document-root = "/home/ez/apps/typo/public/"
server.error-handler-404   = "/dispatch.fcgi"
server.indexfiles           = ( "dispatch.fcgi")
server.errorlog = "/home/ez/logs/error.typo1.log"
   fastcgi.server = ( ".fcgi" =>
      ( "localhost" =>
        ( "socket" => "/home/ez/tmp/typo1.socket",
                             "min-procs" => 1,
                             "max-procs" => 5,
          "bin-path" => "/home/ez/apps/typo/public/dispatch.fcgi",
          "bin-environment" => ( "RAILS_ENV" => "production" )
   )))
}

$HTTP["host"] =~ "myapp2.com" {
server.document-root = "/home/ez/apps/typo2/public/"
server.error-handler-404   = "/dispatch.fcgi"
server.indexfiles           = ( "dispatch.fcgi")
server.errorlog = "/home/ez/logs/error.typo2.log"
   fastcgi.server = ( ".fcgi" =>
      ( "localhost" =>
        ( "socket" => "/home/ez/tmp/typo2.socket",
                             "min-procs" => 1,
                             "max-procs" => 5,
          "bin-path" => "/home/ez/apps/typo2/public/dispatch.fcgi",
          "bin-environment" => ( "RAILS_ENV" => "production" )
   )))
}

$HTTP["host"] =~ "myapp3.com" {
server.document-root = "/home/ez/apps/typo3/public/"
server.error-handler-404   = "/dispatch.fcgi"
server.indexfiles           = ( "dispatch.fcgi")
server.errorlog = "/home/ez/logs/error.typo3.log"
   fastcgi.server = ( ".fcgi" =>
      ( "localhost" =>
        ( "socket" => "/home/ez/tmp/typo3.socket",
                             "min-procs" => 1,
                             "max-procs" => 5,
          "bin-path" => "/home/ez/apps/typo3/public/dispatch.fcgi",
          "bin-environment" => ( "RAILS_ENV" => "production" )
   )))
}
################
mimetype.assign             = (
    ".rpm"          =>      "application/x-rpm",
    ".pdf"          =>      "application/pdf",
    ".sig"          =>      "application/pgp-signature",
    ".spl"          =>      "application/futuresplash",
    ".class"        =>      "application/octet-stream",
    ".ps"           =>      "application/postscript",
    ".torrent"      =>      "application/x-bittorrent",
    ".dvi"          =>      "application/x-dvi",
    ".gz"           =>      "application/x-gzip",
    ".pac"          =>      "application/x-ns-proxy-autoconfig",
    ".swf"          =>      "application/x-shockwave-flash",
    ".tar.gz"       =>      "application/x-tgz",
    ".tgz"          =>      "application/x-tgz",
    ".tar"          =>      "application/x-tar",
    ".zip"          =>      "application/zip",
    ".mp3"          =>      "audio/mpeg",
    ".m3u"          =>      "audio/x-mpegurl",
    ".wma"          =>      "audio/x-ms-wma",
    ".wax"          =>      "audio/x-ms-wax",
    ".ogg"          =>      "audio/x-wav",
    ".wav"          =>      "audio/x-wav",
    ".gif"          =>      "image/gif",
    ".jpg"          =>      "image/jpeg",
    ".jpeg"         =>      "image/jpeg",
    ".png"          =>      "image/png",
    ".xbm"          =>      "image/x-xbitmap",
    ".xpm"          =>      "image/x-xpixmap",
    ".xwd"          =>      "image/x-xwindowdump",
    ".css"          =>      "text/css",
    ".html"         =>      "text/html",
    ".htm"          =>      "text/html",
    ".js"           =>      "text/javascript",
    ".asc"          =>      "text/plain",
    ".c"            =>      "text/plain",
    ".conf"         =>      "text/plain",
    ".text"         =>      "text/plain",
    ".txt"          =>      "text/plain",
    ".dtd"          =>      "text/xml",
    ".xml"          =>      "text/xml",
    ".mpeg"         =>      "video/mpeg",
    ".mpg"          =>      "video/mpeg",
    ".mov"          =>      "video/quicktime",
    ".qt"           =>      "video/quicktime",
    ".avi"          =>      "video/x-msvideo",
    ".asf"          =>      "video/x-ms-asf",
    ".asx"          =>      "video/x-ms-asf",
    ".wmv"          =>      "video/x-ms-wmv",
    ".bz2"          =>      "application/x-bzip",
    ".tbz"          =>      "application/x-bzip-compressed-tar",
    ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
   )

On Feb 2, 2006, at 3:38 PM, Amr Malik wrote:

> etc. etc.
> different domain names (resolving to the same dedicated box) off of
> simply.
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
1b9da5824527b6f67e5305c9f6867fc7?d=identicon&s=25 Amr Malik (Guest)
on 2006-02-03 03:23
(Received via mailing list)
--- Ezra Zygmuntowicz <ezra@yakima-herald.com> wrote:

>
... content clipped ...

Thanks for your responses Ezra and everyone!

Ezra, this was actually my next question (running all 3 apps
independently so
one reboot doesn't affect the others) :)

If I wanted to go with 3 IP's/ 3 lightys scenario, how would I bind a
separate
lighttpd instance to each different IP? Sorry if its a very basic
question, I
have only used the script/server mechanism to start lighty uptil now.

Thanks for all your help!

Amr



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-03 03:32
(Received via mailing list)
Amr-

	You can just put one app in each lighttpd.conf file and then use
this line at the top of the conf outside of your apps $HOST part:

server.bind                = "216.32.90.163"

	Put a different IP in each conf file and it will only bind to that IP.

Cheers-
-EZra



On Feb 2, 2006, at 6:20 PM, Amr Malik wrote:

>>
> If I wanted to go with 3 IP's/ 3 lightys scenario, how would I bind
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
1b9da5824527b6f67e5305c9f6867fc7?d=identicon&s=25 Amr Malik (Guest)
on 2006-02-03 03:44
(Received via mailing list)
Awesomeness!
    Thanks so much Ezra, truly appreciated! saved me a laborius trip to
virtualmin-ville!!

Thanks,

Amr

--- Ezra Zygmuntowicz <ezra@yakimaherald.com> wrote:

> -EZra
> >> with the config file I pasted below. Or since you have multiple IP's
> >
> > Thanks for all your help!
> > Rails mailing list
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-03 11:22
(Received via mailing list)
On 2/2/06, Ezra Zygmuntowicz <ezra@yakimaherald.com> wrote:
> Amr-
>
>         You can just put one app in each lighttpd.conf file and then use
> this line at the top of the conf outside of your apps $HOST part:
>
> server.bind                = "216.32.90.163"
>
>         Put a different IP in each conf file and it will only bind to that IP.

My first thought was "wow, you should really write up a howto about
all this stuff"....

And then, five seconds later, "oh yeah, he's already doing that."
Ee62cc31168a5fea18fe71ed337ad3c3?d=identicon&s=25 Jean Carlo Schechnner (Guest)
on 2006-02-03 16:12
(Received via mailing list)
I think you have to do this

@client_pages, @clients = paginate :clients, :per_page => 10,
:conditions =>
"first_name = 'Elliot'"
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-03 18:40
(Received via mailing list)
On Feb 3, 2006, at 2:20 AM, Joe Van Dyk wrote:

>> to that IP.
>
> My first thought was "wow, you should really write up a howto about
> all this stuff"....
>
> And then, five seconds later, "oh yeah, he's already doing that."
>

Joe-

	Yep, the book is coming along nicely. I am right on target for a
beta pdf release in March ;-)

Cheers-
-Ezra

>>>> with the config file I pasted below. Or since you have multiple
>>> ... content clipped ...
>>> question, I
>>> Do You Yahoo!?
>> Yakima Herald-Republic Newspaper
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
This topic is locked and can not be replied to.