routing

How to generate the proper `url_for` a nested resource?

*爱你&永不变心* 提交于 2019-12-06 08:27:29
问题 I am using Ruby on Rails 3.2.2 and I would like to generate a proper url_for URL for a nested resource. That is, I have: # config/routes.rb resources :articles do resources :user_associations end # app/models/article.rb class Article < ActiveRecord::Base ... end # app/models/articles/user_association.rb class Articles::UserAssociation < ActiveRecord::Base ... end Note : generated named routes are like article_user_associations , article_user_association , edit_article_user_association , ...

Rails routing - how to add scope param to url_for helper?

拟墨画扇 提交于 2019-12-06 07:38:47
I have resource bio and in views and link for add new bio is: = link_to "Add new bio", [:new, :admin, :bio] If I put resource :bio to scope like this: namespace :admin do scope "/:bio_type", :defaults => {:bio_type => "company"} do resources :bios end end This doesn't work = link_to "Add new bio", [:new, :admin, :bio, { bio_type: params[:bio_type] }] My question is how can I add scoped param to url_for helper? And can rails do this by default? p.s. new_admin_bio_path({bio_type: params[:bio_type]}) works fine, but it's just curious I believe you cannot make this with array params to link_to .

URI routing not working (multilingual)

雨燕双飞 提交于 2019-12-06 07:37:55
How are you? Summary: I'm trying to move my website from localhost to amazon-ec2 and almost any route brings "The requested URL example.com/xxx/yyy/ was not found on this server. Context: Using codeigniter structure in public_html, applications and system. Web language in the URI. Example: localhost/public_html/es/main. For testing, one page (register) it's routed differently: localhost/public_html/admin/register. The page works from localhost. Issue: I uploaded the page to my EC2, and when I try to access, almost every page shows the 404 error. Just register page works, but only if I call it

Force 'www' in Rails3 hosted on Heroku without .htaccess

筅森魡賤 提交于 2019-12-06 06:52:52
问题 I was wondering if there was a Rack alternative to forcing the 'www' in the URL since Heroku doesn't use .htaccess files. Maybe even a nice way to do it in routes? Thanks 回答1: A quick Google search reveals this Rack middleware, which appears to do exactly what you want. 回答2: In your ApplicationController, you can simply create a before filter: before_filter :force_www! protected def force_www! if Rails.env.production? and request.host[0..3] != "www." redirect_to "#{request.protocol}www.#

Categories of controllers in MVC Routing? (Duplicate Controller names in separate Namespaces)

自闭症网瘾萝莉.ら 提交于 2019-12-06 06:50:19
问题 I'm looking for some examples or samples of routing for the following sort of scenario: The general example of doing things is: {controller}/{action}/{id} So in the scenario of doing a product search for a store you'd have: public class ProductsController: Controller { public ActionResult Search(string id) // id being the search string { ... } } Say you had a few stores to do this and you wanted that consistently, is there any way to then have: {category}/{controller}/{action}/{id} So that

Angular stateParams to controller, $urlRouterProvider

让人想犯罪 __ 提交于 2019-12-06 06:35:45
I'm building an app with Ionic and AngularJS. Now I have a page with a list of items. Each item has an ID, and so a click results in something like this: /item/1 or /item/2 where 1 and 2 are ID's. Now I have the default state like this, for the homepage with this list: .state('app.home', { url: "/home/", views: { 'menuContent': { templateUrl: "app/home.html" }, }, controller: 'HomeCtrl' }) What I want is to pass the paramater to the controller. What I found is the following solution, but this isn't working. The reason is that it doesn't know which controller to use (in above example, HomeCtrl

Is it possible to dynamically remove a level of rails resource nesting?

十年热恋 提交于 2019-12-06 06:04:05
I need routing to work for both a hosted and whitelabel version of a rails app. Both versions are running off the same codebase and on the same server so the routing needs to figure things out but it's not clear to me how to achieve this. I'm building a job board. Each company signing up can create their own company profile on the site. If they get a paid premium version they can use their own CNAME'd URL and serve the job board off one of their subdomains. All pretty standard stuff. What routes need to look like on the main site http://jobsrus.com/companies/company-name # e.g. http://jobsrus

Rails routing without resource name

半世苍凉 提交于 2019-12-06 05:54:28
问题 My rails app has a Section model and a Page model. A section has many pages. # section.rb class Section < ActiveRecord::Base has_many :pages end # page.rb class Page < ActiveRecord::Base belongs_to :section end Assuming I have a Section with slug 'about', and that section has three pages with slugs 'intro', 'people', 'history,' a url with typical routing might look something like this: http://example.com/sections/about/pages/intro http://example.com/sections/about/pages/people http://example

Is there a callback in ember.js which I can use to run code after all views are rendered after state transition?

淺唱寂寞╮ 提交于 2019-12-06 05:52:39
问题 I've got application view consisting of three outlets: <script type="text/x-handlebars" data-template-name="application"> {{outlet header}} {{outlet content}} {{outlet footer}} </script> which render their own views (simplified): <script type="text/x-handlebars" data-template-name="header"> <a href="#" data-role="button" data-icon="arrow-l" data-iconpos="notext" {{action changeDate view.prevDate href=true}}>Prev</a> {{view.model.weekDay}} <a href="#" data-role="button" data-icon="arrow-r"

PHP REST API Routing

送分小仙女□ 提交于 2019-12-06 05:34:12
问题 I have been looking at APIs and developing a REST API for a project that we are working on. The API only accepts connections from one source in JSON format, I understand that bit fine. If understand the majority of what is being said, however I don't understand the 3rd code example down and where the routing information would go. The example they have provided is: $data = RestUtils::processRequest(); switch($data->getMethod) { case 'get': // retrieve a list of users break; case 'post': $user