Hi, I have been learning ROR for less than a month. I am having problems getting my head around models and controllers. I want to have 2 tables called players and results in my DB. I want to be able to access them in a browser to show all the records by /player and /result. I also want to use /admin to add new players and results. How would I go about this? I am not asking for specific code, just the commands I need to generate the appropriate controllers and models. 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here are some good cheat sheets and other such stuff that helped me when I first got started and believe me it gets easier but it does take time to wrap your mind about how everything works: http://www.slash7.com/ Look at the "Goodies" http://blog.invisible.ch/files/rails-reference-1.1.pdf http://www.blainekendall.com/uploads/RubyOnRails-Cheatsheet-BlaineKendall.pdf and this book helped me a lot when I first started out: http://www.sitepoint.com/books/rails1/ The cheatsheets should give you a good start and should answer your questions. Good luck. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First let me say there are many different ways to implement this. It depends on your particular needs. So I will try to break down the conventional approach presented by Ruby on Rails. You are describing two resources: a Player and a Result. This would be represented by two models and in turn two database tables. The models would be named Player and Result. The database tables and resource routes would be the plural of those (i.e. players and results). You would have the the following routes for manipulating those resources: GET: /players GET: /players/1 POST: /players PUT: /players/1 DELETE: /players/1 When you GET (as in HTTP GET method) on /players you are asking for a list of players. This will be handled by the index action and players/ index.html.erb page in your controller and view respectively. If you POST to that same /players route you would be asking the controller to create a new Player instance and save it to the players database table. This is handled by the create action in your players_controller. Of course, there also needs to be a way to ask (GET) the form used to provide the attributes for a new player. You accomplish this by sending a GET request to the /players/new path. This means "Get the form used to submit a new player." Similarly, If you PUT to the path /players/1 you are asking the players_controller to update an existing player who''s id is 1. Like new there is also the /players/1/edit used to get the edit form for the player with id 1 where the user would be presented the template represented by players/edit.html.erb. Now this is an over simplification of how the system works, but hopefully it will give you some direction on what to study. My first suggestion is to find and read all you can on Model-View-Controller design pattern and on Representation State Transfer (REST). Without a good understanding of these architectures you will be constantly confused by Ruby on Rails. P.S. You mentioned having an admin interface. There is a facility in Rails to supporting admin interfaces separately from standard interfaces, but I''m afraid that topic is too advanced for your current level of experience with Rails. My suggestion would be to avoid the notion of a separate admin interface until you understand the basics of Rails. On Jul 28, 9:17 am, Rob Pa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I have been learning ROR for less than a month. I am having problems > getting my head around models and controllers. > > I want to have 2 tables called players and results in my DB. I want to > be able to access them in a browser to show all the records by /player > and /result. I also want to use /admin to add new players and results. > > How would I go about this? I am not asking for specific code, just the > commands I need to generate the appropriate controllers and models. > > Thanks > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Thanks for the help. I started my project again creating the models and controllers for each section. What I didnt realise is that I had to put; map.resources :player map.resources :result into the routes section. It it now works when I access /player and /result but is this the only and suitable way to do it? Thanks a lot -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Now, following on from Agile Web Developments with Rails, I have created a user model and login controller, with login/login login/add_user etc.. But I cant seem to access login/add_user but I can access login/index. I get this error: Unknown action No action responded to show How would I get this 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I now got it working. I had map.resources :login which will have created the show thing. I have now removed all the map.resources that I had and everything now works. But Im puzzled why it wouldnt work to start with, i.e. when I used to access /login it never worked. Thanks a lot -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Now, I want to add a review section, so I do; generate/model Review title:string comment:text date:date The database table is created fine. So I then make the controller; generate/controller reviews index. This works fine and creates everything. But when I try and access it using /reviews I get; Routing Error No route matches "/reviews" with {:method=>:get} Why? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
One more comment: Don''t forget to stop/start your server after changing anything in routes.rb. It can get very confusing if you forget to do that, as changes you make are not picked up when you''re testing your routes. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Heroku shouldn''t make a difference, however, you may need to check if the server is restarted properly after you change your routes, as the procedure is different than on your local machine. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So with this as my routes.rb all should work fine? ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect ''products/:id'', :controller => ''catalog'', :action => ''view'' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # map.purchase ''products/:id/purchase'', :controller => ''catalog'', :action => ''purchase'' # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # map.resources :products # Sample resource route with options: # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # Sample resource route with sub-resources: # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # Sample resource route within a namespace: # map.namespace :admin do |admin| # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # admin.resources :products # end # You can have the root of your site routed with map.root -- just remember to delete public/index.html. #map.root :controller => "index" # See how all your routes lay out with "rake routes" # Install the default routes as the lowest priority. map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---