rails-routing

Wildcard matching for Rails API Versioning causes infinite redirect

眉间皱痕 提交于 2019-12-13 14:50:25
问题 I was following the excellent solution posted here regarding versioning an API using Rails routing, but I keep running into an infinite redirect. Here is a section of my routes.rb namespace :api do namespace :v1 do resources :books end namespace :v2 do resources :books end match 'v:api/*path', :to => redirect("/api/v2/%{path}") match '*path', :to => redirect("/api/v2/%{path}") end which is virtually the same as the posted answer. Accessing /api/v1/books/list.json works as expected as does api

How to test route constraints with rspec

你。 提交于 2019-12-13 12:25:36
问题 I'm working on an application that will be primarily served as an API (other than a few minor views, such as session/registration, which will be "standard"). I like the approach that was finalized in Railscast #350: Versioning an API, and so followed it. My routes look like: namespace :api, :defaults => {:format => 'json'} do scope :module => :v1, :constraints => ApiConstraints.new(:version => 1, :default => false) do resources :posts, :only => [:create, :show, :destroy, :index] end scope

Rails link_to action with URL parameters

房东的猫 提交于 2019-12-13 03:56:30
问题 If I have a route like so get 'controller/:id/action/:param' => 'Controller#action' How can I use link_to to create a link like <a href="/controller/12345/action/abcde"> ? So far I have gotten link_to 'Link text', {:action => 'action'} To give me <a href="/controller/12345/action"> but using link_to 'Link text', {:action => 'action', :param => 'abcde'} will give me <a href="/controller/12345/action?param=abcde"> 回答1: You can name your route: get 'controller/:id/action/:param' => 'Controller

How to check validation on creation method if its called from specific route?

醉酒当歌 提交于 2019-12-12 23:42:00
问题 I want to validate column presence on creation method if the creation method is called from some other route. For example, If I have following two routes: post 'create_item', to: 'item#create' post 'create_verified_item', to: 'item#create_verified' I need to define in Item model something like this: validates :verified_number, presence: true, if: Item.action_name == "create_verified" Anyone can help? 回答1: Ideally you can add a attribute to item to check that, something like: # model class

Ruby on Rails: Can I route a request directly to a view?

為{幸葍}努か 提交于 2019-12-12 13:34:08
问题 I have an admin section that has a sub-directory of the controllers directory. I.e., the directory app/controllers/admin/ holds a set of files, each containing a controller for handling a separate portion of the admin section. Now, I want to create a very simple ''admin homepage'' that just says something a la "welcome to the admin section", but I want to avoid creating an entire controller for this purpose, or placing the "action" method for this view in some other, arbitrary controller. So,

Submitting a form (no model) and having trouble getting the controller to play its part

寵の児 提交于 2019-12-12 04:48:21
问题 I’ve created a basic framework for webapps (some static pages, user authentication, unit/integration testing with rspec). I’d like to use this as a foundation for future webapps, but I need to setup a way to rename it after cloning it from github. I got some help generating the renaming code here]1, but I'm struggling to figure out how to integrate it. I originally wrote had the renaming code in a rakefile, but now I think maybe it should be in the controller. Unfortunately, I haven't been

How can I get rails routes to match * for the final parameter of my url?

心已入冬 提交于 2019-12-12 02:29:47
问题 I would like to allow a user to automatically login if they use their encrypted password in the url. I have the following url that I would like matched with rails routes: /attendants/update_player_status/game/1/maybe/user_hash/$2a$10$1kY8xvOjkqZJJJGWDd0q2Oeyl7kICSBDPTYzGhkJ6pZnE6YA/nJie where the latter part of the url can have any characters, like * (ie. it can have '/' '$' '*' etc) My routes works but then it bombs out on '/' in the parameter (as seen above): match '/attendants/update

Rails Wicked Gem - Understanding routing

元气小坏坏 提交于 2019-12-12 02:07:02
问题 Okay, so I'm not really understanding nested routing in the wicked gem. So far I have this. I'm not sure if everything is in the right folder or if I'm doing that right. routes.rb resources :events resources :events do resources :build, controller: 'events/build' end controllers/events_controller.rb def create @event = Event.new(event_params) if @event.save flash[:success] = "Event Created!" redirect_to event_build_path(event_id: "event", id: @event.id) # previously had redirect_to event

Rails devise not working for rails 3.2.1 on localhost

橙三吉。 提交于 2019-12-12 01:29:12
问题 I followed each and every single step for devise to work on my localhost as discussed under this tutorial - http://www.slideshare.net/wleeper/devise-and-rails upto page 8 of 22 and I was expecting the same user login form as mentioned on the page 8 but apart from this, i am getting this error- If i keep the comments as it is on routes.rb file, # match ':controller(/:action(/:id))(.:format)' then this message flags - And when i uncomment this line it show this error- Have very less idea about

How do I link an action to a button without creating a route in rails?

a 夏天 提交于 2019-12-11 11:34:47
问题 I have a vote button in my Rails app and to allow a user to vote I've created a route that connects the button and the respective action. Route: /posts/1/vote_up But on other ROR websites I've been analyzing they can accomplish the same thing without creating a route (or at least, without showing it to the public user). An example would be Producthunt, there's a vote button, but when you hover over it, there is no route or URL mapped to it. How does one do that? Can I link an action to a