rails-routing

Routing for sessions#destroy action

泪湿孤枕 提交于 2019-12-23 12:17:58
问题 I'm linking to the destroy action for the Sessions controller like this: <%= link_to "Sign out", session_path, method: :delete %> Routes.rb: resources :sessions, only: [:new, :create, :destroy] Rails complains about the link above: No route matches {:action=>"destroy", :controller=>"sessions"} missing required keys: [:id] How do I link to the destroy action and keeping the REST/resource methodology in Rails when there's no object ID to provide for the link? 回答1: It is best to treat the routes

Ruby on Rails - passing params into 301 redirect in routes.rb

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:01:11
问题 I want to change my existing 'game' routing inside routes.rb, but because of SEO I need also to setup 301 redirect for old links. My old routing: match 'games/:permalink/:id/(:page)' => 'games#show' New routing: match 'gierki/:permalink/(:page)' => 'games#show' Here is redirection which I tried to to do: match 'games/:permalink/:id/(:page)' => redirect {|params| "/gierki/#{params[:permalink]}" + params[:page].nil? ? "" : "/#{params[:page]}" } Above redirect is not working, here is an error:

Rails controller action without a view

天大地大妈咪最大 提交于 2019-12-23 07:41:08
问题 I just want to do a rails action without a view. In my 'routes.rb' resources :pictures do member do post 'dislike' end end In my 'PictureController.rb' this does not work def dislike @picture = Picture.find(params[:id]) @like = Like.find(:user_id => current_user.id, :picture_id => params[:id]) @like.destroy respond_to do |format| format.html { render :action => :show, :id => params[:id], notice: 'You don\'t like this picture anymore.' } format.json { render json: @picture } end end neither do

Rails nested routing issue

时光怂恿深爱的人放手 提交于 2019-12-23 05:05:04
问题 I have Q+A model inside an events model and having issue with understanding how the nested routes work. I'm getting a No route matches {:action=>"create", :controller=>"event_questions" and missing required keys: [:event_id]` My question form sits inside my show.hrml.erb for my event model right now. Some of the relationship stuff is from neo4j gem so it isn't standard but the issue shouldn't be related to that. From what I know, I am posting to /events/events_id/event_questions events

Why does mounting a route in Rails fail with “uninitialized constant API”?

心已入冬 提交于 2019-12-22 06:56:46
问题 I am working on an app that includes an API that is using the grape gem. Here is my Root Class: module API class Root < Grape::API rescue_from :all do |e| Rack::Response.new( [ "Error: #{e.message}" ], 500, { "Content-type" => "text/error" } ).finish end prefix "api" version 'v1', using: :path format :json error_format :json mount ::API::ServiceRequests end end Here is how I am mounting it in routes: mount API::Root => '/' The error I am receiving is: routes.rb:45:in block in ': uninitialized

Determine if Journey::Path::Pattern matches current page

吃可爱长大的小学妹 提交于 2019-12-22 06:37:42
问题 I'm trying to use the method outlined this post in conjunction with url_for to determine if the current path is in a mounted engine, but I'm having a hard time figuring out how exactly to use Journey::Path::Pattern (which is what is returned by the mounted_path method outlined in the other post). class Rails::Engine def self.mounted_path route = Rails.application.routes.routes.detect do |route| route.app == self end route && route.path end end There doesn't seem to be too much discussion on

ActionController::RoutingError: uninitialized constant Api::V1::ApiController

怎甘沉沦 提交于 2019-12-22 05:32:26
问题 I have Rails 5 API project for controlling user tasks and I have the following error but not always for the same controller and route. ActionController::RoutingError: uninitialized constant Api::V1::ApiController I describe you a little bit my project to explain in more detail the error. App structure Routes scope module: 'api' do namespace :v1 do # => Login routes scope module: 'login' do match 'login', to: 'sessions#login', as: 'login', via: :post end # => Team routes scope module: 'team'

Rails 3 w/ Devise: How to set two separate homepages based on whether the user is authenticated or not?

丶灬走出姿态 提交于 2019-12-20 09:47:22
问题 I am using Rails 3 and Devise to create an app where users arrive to the website and are shown a homepage containing a login and a signup form. This page has its own controller ("homepage") so it's route is root :to => "homepage#index" I want to display a different homepage if the users are already logged in. This would account to having the root point to root :to => "dashboard#index" Is there a way to have a conditional route in routes.rb, that would allow me to check whether the user is

/YYYY/MM/Title-Slug URL structure with Friendly_Id Solution Chokes on #new and #edit

我的梦境 提交于 2019-12-20 04:38:12
问题 I have a partial solution to my previous issue which is correctly displaying the posts#index and posts#show routes, but is choking after creating a post: ActionController::UrlGenerationError in PostsController#create No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id, :month, :year] Extracted source (around line #32): 30 respond_to do |format| 31 if @post.save 32 format.html { redirect_to post_path, notice: 'Post was successfully created.' } 33 format.json {

In rails routes, nested resources is causing white screen

自闭症网瘾萝莉.ら 提交于 2019-12-13 23:55:59
问题 I have two models: Schedule and Project. Schedule belongs_To Project and Project has_one schedule. The routes for schedule and Project are nested like this: get 'projects/current', to: 'projects#show_current', as: :current_freelancer_projects resources :projects do resources :schedules end When I run rake routes, it says the path to make a new schedule is: new_project_schedule GET /projects/:project_id/schedules/new(.:format) The problem is, when I include a link to new_project_Schedule on a