Hi, I m very new to Ruby. I bought a book "Ruby on Rails" and I think I understand some concepts. My question is : Is there a way to not use "Cookies" or "Sessions Variables" to keep some information about the user. I ask this question because I would like to prevent some cases where the user browser won''t accept cookies. I m from Asp 3.0, and I usually use a UID that I send thru my urls for each on my links. (this unique identifier stored inside a table) Something like http://www.mywebsite/contact.asp?sid=blablabla Do you have any advice about this topic ? Regards Stan Ps : ok my English is not perfect but :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060704/1cc6f0fd/attachment-0001.html
Stan Sainte-Rose wrote:> Is there a way to not use "Cookies" or "Sessions Variables" to keep some > information about the user.This post may help you out http://lists.rubyonrails.org/pipermail/rails/2005-January/001415.html -- Posted via http://www.ruby-forum.com/.
Hello everybody, I have created a string database with a table that allows me to populate my database by entering strings one by one. I also however want it to take in batch files to populate the database (the format is either .rc (for windows) and localizable.strings (for mac)). so far I have the browse botton to get the file for upload, but from here I am confused. I don''t know how I will be reading or extracting those strings from the batch file. am I looking at this the right way or is there an easier way to solve my problem? Thanks for your input, ricardo -- Posted via http://www.ruby-forum.com/.
Can you parse the file line by line and do an insert for each line? On Jul 18, 2006, at 11:32 AM, Ricardo Ricardito wrote:> Hello everybody, > > I have created a string database with a table that allows me to > populate > my database by entering strings one by one. I also however want it to > take in batch files to populate the database (the format is either .rc > (for windows) and localizable.strings (for mac)). so far I have the > browse botton to get the file for upload, but from here I am confused. > I don''t know how I will be reading or extracting those strings from > the > batch file. am I looking at this the right way or is there an easier > way to solve my problem? > > Thanks for your input, > > ricardo > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Take this code: <% for news in @news %> <p class="title"><%= news.title %></p> <p><%=h news.date.strftime("%A, %B %d, %Y ") %></p> <p><%= news.copy %></p> <% end %> -- Posted via http://www.ruby-forum.com/.
OOPS! Take this code: <% for news in @news %> <p class="title"><%= news.title %></p> <p><%=h news.date.strftime("%A, %B %d, %Y ") %></p> <p><%= news.copy %></p> <% end %> What if I just wanted the most recent news item to be used instead of ALL of them. Sorry, this is a dumb question but i''m new! mk -- Posted via http://www.ruby-forum.com/.
In the controller that calls the view add: @news = News.find(:first, :order => "date DESC") so @news will only contain the latest record. Mason Kessinger wrote:> OOPS! > > Take this code: > > <% for news in @news %> > <p class="title"><%= news.title %></p> > <p><%=h news.date.strftime("%A, %B %d, %Y ") %></p> > <p><%= news.copy %></p> > <% end %> > > What if I just wanted the most recent news item to be used instead of > ALL of them. > > Sorry, this is a dumb question but i''m new! > > mk-- Posted via http://www.ruby-forum.com/.
This is so simple. And really helps me to see the whole MCV idea. I''m just a simple designer who is pretty much new to the development gig. If you don''t mind my asking? How would I be able to call up a) the first two items in news b) the first and the third item in news c) the first and the last item in news? Thanks for your help! Fran?ois Montel wrote:> In the controller that calls the view add: > > @news = News.find(:first, :order => "date DESC") > > so @news will only contain the latest record. > > Mason Kessinger wrote: >> OOPS! >> >> Take this code: >> >> <% for news in @news %> >> <p class="title"><%= news.title %></p> >> <p><%=h news.date.strftime("%A, %B %d, %Y ") %></p> >> <p><%= news.copy %></p> >> <% end %> >> >> What if I just wanted the most recent news item to be used instead of >> ALL of them. >> >> Sorry, this is a dumb question but i''m new! >> >> mk-- Posted via http://www.ruby-forum.com/.
On 7/25/06, Mason Kessinger <masonkessinger@gmail.com> wrote:> > This is so simple. And really helps me to see the whole MCV idea. I''m > just a simple designer who is pretty much new to the development gig.If you don''t mind my asking?> > How would I be able to call up > > a) the first two items in newsb) the first and the third item in news> c) the first and the last item in news? > >I''m a newbie too, and there are experts on this mailing list who can give you much better solutions than I, but off the top of my head, you could create arrays for options a) b) and c) in your controller, and then just show them in your view. For example: in your controller: @news = News.find(:all, :order => ''date ASC'') @first_two_news = [ @news[0], @news[1] ] @first_and_third_news = [ @news[0], @news[2] ] @first_and_last_news = [ @news[0], @news[@news.length-1] ] Note: @news is a collection of objects, and collections and arrays in Ruby start with 0 instead of 1. That''s why @news(0) is the first record in the array. The last record would be @news.length (the number of records in @news) minus 1 (since you''re starting with 0). Alternatively, you can just have the first line above in your controller, and then in your view you could have an IF statement that would evaluate each record as you process it, and then do something or not do something with it accordingly. -- "Impossible is nothing." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060726/317f0a77/attachment.html
I have a following simple model structure User belongs_to Address Address has_one User I therefore have a address_id foreign key in users table. I am trying to find all users who are in a particular city (in the addresses table). The addresses table does not have a user_id foreign key. What is the best way to accomplish that? I did something like Address.find_by_city("San Jose") but then I get a list of records - how do I extract the corresponding user records most efficiently? I could go in a loop and for each address record found above do a User.find_by_address_id and pass in the address_id - but that would be very inefficient. There has to be something simple and quick for this. Thanks, Sanjay. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060731/8a95a90a/attachment.html
> I have a following simple model structure > > User belongs_to Address > Address has_one User > > I therefore have a address_id foreign key in users table. I am trying to > find all users who are in a particular city (in the addresses table). The > addresses table does not have a user_id foreign key. What is the best way to > accomplish that? > > I did something like Address.find_by_city("San Jose") but then I get a list > of records - how do I extract the corresponding user records most > efficiently? I could go in a loop and for each address record found above do > a User.find_by_address_id and pass in the address_id - but that would be > very inefficient. There has to be something simple and quick for this.Unless it''s because I''m hungry and not thinking straight, I think you have your model/db mixed up... User has_one Address Address belongs_to User And you have a ''user_id'' field in your ''addresses'' table. You can then do: Address.find_by_city("San Jose", :include => [:user]) -philip
Philip Hallstrom wrote:>> I did something like Address.find_by_city("San Jose") but then I get a list >> of records - how do I extract the corresponding user records most >> efficiently? I could go in a loop and for each address record found above do >> a User.find_by_address_id and pass in the address_id - but that would be >> very inefficient. There has to be something simple and quick for this. > > Unless it''s because I''m hungry and not thinking straight, I think you > have > your model/db mixed up... > > User has_one Address > Address belongs_to User > > And you have a ''user_id'' field in your ''addresses'' table. > > You can then do: > > Address.find_by_city("San Jose", :include => [:user]) > > -philipThanks Philip. I had that upside down. However I ran into a subsequent problem. Normally I would be able to create an array like following @all_needed_users = User.find(:all, :conditions => "city = ''San Jose''").map{|c| [c.username, c.id]} and I would have an @all_needed_users array to be used for option_tags in a select_tag In this case I did the following @all_needed_users = Address.find(:all, :conditions => "addresses.company_id = 12 and addresses.city = ''Bangalore''" , :include => [:user]).map{|c| [c.username, c.id]} and there are two problems - 1. The c.id is ambiguous as both addresss and user tables return the id column 2. The SQL generated indicates that all column names are now named to something else as shown in the SQL below and therefore c.username and c.id are not understood. So the question is whether there is a simple way like the example above to create an array that I can use for option_tags? SQL generated now is - SELECT addresses.`id` AS t0_r0, addresses.`street` AS t0_r1, addresses.`city` AS t0_r2, addresses.`zip` AS t0_r3, addresses.`company_id` AS t0_r4, addresses.`user_id` AS t0_r5, users.`id` AS t1_r0, users.`firstname` AS t1_r1, users.`lastname` AS t1_r2, users.`created_at` AS t1_r3, users.`login_count` AS t1_r4, users.`last_login_at` AS t1_r5, users.`username` AS t1_r6, users.`hashed_pwd` AS t1_r7, users.`salt` AS t1_r8 FROM addresses LEFT OUTER JOIN users ON users.id = addresses.user_id WHERE (addresses.company_id = 12 and addresses.city = ''Bangalore'') Lastly is there a way to restrict the number of columns being returned by the :include option - I don''t see a way to do that. TIA, ST -- Posted via http://www.ruby-forum.com/.
Hi all- I''m a complete Ruby/Rails newbie, and I''m trying to find a good resource for explaining how to implement forms using Rails. Specifically, I need to have a series of select boxs that perform an Ajax-style update depending on selection. I have seen a lot of partial code snippets, but nothing definitive. Is there a good resource out there for learning in-depth Ajax programming using Rails? Thanks, ~ Shanan -- Shanan Suding | shanan.suding@sun.com | (602) 357-4327 (x51609) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"Crucify the ego before it''s far too late And leave behind this place so negative and blind and cynical And you will come to find that we are all one mind Capable of all that''s imagined and all conceivable" - Maynard James Keenan, Tool
On 8/1/06, Shanan Suding <Shanan.Suding@sun.com> wrote:> I''m a complete Ruby/Rails newbie, and I''m trying to find a good resource > for explaining how to implement forms using Rails. Specifically, I need > to have a series of select boxs that perform an Ajax-style update > depending on selection. I have seen a lot of partial code snippets, but > nothing definitive. Is there a good resource out there for learning > in-depth Ajax programming using Rails?http://oreilly.com/catalog/rjsrails/ -- Greg Donald http://destiney.com/