Tag: routing

Rails路由出现在路由中但抛出404

我正在尝试向现有的控制器/操作添加一个简单的路由,但奇怪的是,即使路径似乎存在,我也会收到404错误。 这是我的routes.rb的相关部分: # Wines scope ‘wine’ do get ‘/’, to: ‘wines#index’, as: ‘wine_index’ get ‘/:collection’, to: ‘wines#collection_detail’, as: ‘collection_detail’ get ‘/:collection/:slug’, to: ‘wines#wine_detail’, as: ‘wine_detail’ get ‘/:style’, to: ‘wines#style_detail’, as: ‘style_detail’ end 这似乎是正确的,因为这是我在检查时看到的内容: $ rake routes => Prefix Verb URI Pattern Controller#Action wine_index GET /wine(.:format) wines#index collection_detail GET /wine/:collection(.:format) wines#collection_detail wine_detail GET /wine/:collection/:slug(.:format) wines#wine_detail style_detail […]

rails中的更新路由对after_action反应不佳?

class FrogsController < ApplicationController before_action :find_frog, only: [:edit, :update, :show, :destroy] after_action :redirect_home, only: [:update, :create, :destroy] def index @frogs = Frog.all end def new @ponds = Pond.all @frog = Frog.new end def create @frog = Frog.create(frog_params) end def edit @ponds = Pond.all end def update @frog.update_attributes(frog_params) end def show end def destroy @frog.destroy end […]

与Rails中的url_for相反的是什么? 获取路径并生成解释路线的函数?

大脑有点油炸….我如何得到:控制器的哈希和来自relative_path的动作? 这基本上与url_for相反。 在下面的例子中,“some_function”是我正在寻找的神秘函数名称……我知道它很简单,只是记不住或者似乎无法在文档中找到它。 像这样: some_function(‘/posts/1/edit’) => {:controller => ‘posts’, :action => ‘edit’, :id => ‘1’}

如何在Rails路由中使用正则表达式进行重定向?

我在routes.rb中尝试重写规则可能是不言自明的: match “/:user/:photo-thumb.png” => redirect(“/%{user}/photos/%{photo}/image?style=thumb”), :photo => /[a-zA-Z]+/ 我想将mysite.com/alice/foo-thumb.png之类的内容重定向到mysite.com/alice/photos/foo/image?style=thumb 但上述尝试是错误的。 修理它的任何想法?

ArgumentError:参数数量错误(1表示2)

我是Rails,MVC和CRUD的新手,我正在尝试使用更新方法来更改post的投票数量。 我的post控制器更新方法中有以下代码: def update @post = Post.find(params[:id]) if params[:vote] == ‘up’ @post.update_column(:ups => @post[:ups] + 1) elsif params[:vote] == ‘down’ @post.update_column(:downs => @post[:downs] + 1) end flash[:notice] = “Thanks for voting! This helps us determine important issues in our schools.” redirect_to ‘Posts#index’ end 我的routes.rb中有以下代码: OpenMCJC::Application.routes.draw do root :to => ‘posts#index’ resources :posts match ‘/posts/:id/:vote’, :to […]

rails 3.1 ActionController :: RoutingError(没有路由匹配“/assets/rails.png”):

标准的新rails应用程序出现了rails.png的问题 ActionController::RoutingError (No route matches [GET] “/assets/rails.png”): 我已经尝试将.png文件移动到资产和资产/图像中的各个位置以及较旧的地方“公共”或“公共/图像”并更改页面但没有任何帮助。 如果您已经看到并解决了这个问题,请回答。 我自己尝试过20种不同的组合。 版本:’rails’,’3.1.0.rc4′