nested-resources

Rails - nesting resource with two parents

别来无恙 提交于 2019-12-05 02:48:37
问题 Say I have a child model with two parent models: Event has_many tickets Person has_many tickets Ticket belongs_to Event Ticket belongs_to Person Routes are mapped so Ticket always nests within Event or Person: resource :people do resources :tickets end resources :events do resources :tickets end How do I scope my ticket_Controller CRUD actions by the parent resource? Right now I'm testing for params and using conditional statements: class TicketController before_filter :get_person before

Rails: Nested resources conflict, how to scope the index action depending on the called route

左心房为你撑大大i 提交于 2019-12-04 17:40:39
问题 Imagine you have two defined routes: map.resources articles map.resources categories, :has_many => :articles both accessible by helpers/paths articles_path # /articles category_articles_path(1) # /category/1/articles if you visit /articles , index action from ArticlesController is executed. if you visit /category/1/articles , index action from ArticlesController is executed too. So, what is the best approach for conditionally selecting only the scoped articles depending on the calling route?

Rails 4, strong parameters, nested resources, build and undefined method permit

谁说我不能喝 提交于 2019-12-04 16:43:50
I am unable to get rails 4, strong parameters to work with nested resources via build. Any suggestions would be very welcome. RSPEC shows me Creating Actions Creating an action Failure/Error: click_button "Create Action" NoMethodError: undefined method permit' for "create":String # ./app/controllers/actions_controller.rb:24:in action_params' # ./app/controllers/actions_controller.rb:10:in create' # ./spec/features/creating_actions_spec.rb:16:in block (2 levels) in ' My Browser shows me: NoMethodError in ActionsController#create undefined method `permit' for "create":String Extracted source

form for nested resource

不问归期 提交于 2019-12-04 05:09:52
I have gone through tons of the form_for nested resource questions and can't get any of the solutions to work for me. I figured its time to ask a personalized question. I have two models, jobs and questions, jobs has_many questions and questions belong_to jobs. I used scaffolding to create the controllers and models then nested the resources in the routes.rb. root :to => "pages#home" resources :jobs do resources :questions end get "pages/home" get "pages/about" get "pages/contact" class Job < ActiveRecord::Base has_many :questions end class Question < ActiveRecord::Base belongs_to :job end

Rails Nested Singular Resource Routing

大兔子大兔子 提交于 2019-12-03 22:59:39
I have a simple User model with a singular nested Profile resource so in my routes.rb I have: resources :users do resource :profile, :only => [:edit, :update, :show] end This generates the expected routes: edit_user_profile GET /users/:user_id/profile/edit(.:format) {:action=>"edit", :controller=>"profiles"} user_profile GET /users/:user_id/profile(.:format) {:action=>"show", :controller=>"profiles"} user_profile PUT /users/:user_id/profile(.:format) {:action=>"update", :controller=>"profiles"} I've created a simple controller update method that updates the model and then redirects upon

nested routes and form_for and models using has_one and belongs_to

蹲街弑〆低调 提交于 2019-12-03 21:27:02
问题 How to map out has_one model with nested routes and how to add a form_for for /localhost:3000/users/1/profile/new,html.erb following RESTful database? User has one Profile. Models class Profile < ActiveRecord::Base attr_accessible :name, :surname belongs_to :user end class User < ActiveRecord::Base attr_accessible :email, :email_confirmation, :password, :password_confirmation has_secure_password has_one :profile, dependent: :destroy end resources :users do resources :profiles (note: has_one

Rails - nesting resource with two parents

南楼画角 提交于 2019-12-03 20:26:02
Say I have a child model with two parent models: Event has_many tickets Person has_many tickets Ticket belongs_to Event Ticket belongs_to Person Routes are mapped so Ticket always nests within Event or Person: resource :people do resources :tickets end resources :events do resources :tickets end How do I scope my ticket_Controller CRUD actions by the parent resource? Right now I'm testing for params and using conditional statements: class TicketController before_filter :get_person before_filter :get_event def index if @person do ... elsif @event do ... end respond_to ... end end That seems a

RESTful API routes design: nested vs. non-nested

只愿长相守 提交于 2019-12-03 15:50:07
问题 My question is about the advantages of nesting resources when building URLs for API purposes. Consider the following two alternatives for accessing an employee resource: /api/employees?department=1 # flat Vs. /api/departments/1/employees # nested Now consider the task of developing a general purpose library to access REST resources from an API. If all routes were flat, such a REST wrapper library would only need to know the name of the resource being accessed: store.query('employees',

Does anybody have any tips for managing polymorphic nested resources in Rails 3?

安稳与你 提交于 2019-12-03 08:16:21
In config/routes.rb: resources :posts do resources :comments end resources :pictures do resources :comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible with Rails 3 yet as I would like), and comments are an embedded resource (mongoid can't yet handle polymorphic relational resources), which means that I do need the parent resource in order to find the comment. Are there any elegant ways to handle some of the following problems: In my controller, I need to find the parent before finding the comment: if params

Rails 3 - Best way to handle nested resource queries in your controllers?

喜你入骨 提交于 2019-12-03 07:56:49
问题 If there's one thing I've learned about Rails 3 is if I'm having a hard time doing something, I'm probably doing it wrong. So I'm looking for help. I have a few models which are related in a many to many relationship. I am able to create the associations in the models without a problem. My problem lies in how to build the controllers to work with these relationships. I'll try and give an example if you don't see where I'm going with this. For instance... class Account < ActiveRecord::Base has