1
coordinates GET    /coordinates(.:format)          coordinates#index
                POST   /coordinates(.:format)          coordinates#create
 new_coordinate GET    /coordinates/new(.:format)      coordinates#new
edit_coordinate GET    /coordinates/:id/edit(.:format) coordinates#edit
     coordinate GET    /coordinates/:id(.:format)      coordinates#show
                PUT    /coordinates/:id(.:format)      coordinates#update
                DELETE /coordinates/:id(.:format)      coordinates#destroy
  tweets_search GET    /tweets/search(.:format)        tweets#search
   tweets_index GET    /tweets/index(.:format)         tweets#index

class TweetsController<ApplicationController

  def index
#include 'coordinates_controller.rb'
   include SearchHelper
include ParamasHelper
    @sql=a.search
    @tweets=Tweets.paginate_by_sql(sql, :@page, :per_page => @per_page ).all
  end
end

在我的 Rails 应用程序中,我有两个名为Coordinates和的表Tweets。我有四个动作要呈现。

我的routes.rb档案

Tweetsblog2::Application.routes.draw do
resources :tweets, :coordinates
get "tweets/show"
get "tweets/index"
match "/tweets/show" => "tweets#show"
match "/tweets/index" => "tweets#index"

每当我导航到 时http://localhost:3000/tweets,它都会显示,tweets/index而不是 显示tweets/show我使用不同名称得到的相同错误。

当我导航到 时http://localhost:3000/tweets/show,它正在给予ArgumentError in TweetsController#show

当我导航到http://localhost:3000/tweets/index它给予ArgumentError in TweetsController#show同样的东西

我的代码show.html.erb

<%= form_tag({controller: "tweets", action:"index" }, method: "get") do  %>
  <%= label_tag(:search, "search for:") %>
  <%= text_field_tag(:show) %>
  <%= text_field_tag(:search) %>
  <%= submit_tag("get results ") %>
<% end %>

我的代码index.html.erb

<%= will_paginate @tweets %>
<% @tweets.each do |tweets| %>
<ul>
  <li><%= tweets.id %></li>
  <li><%= tweets.tweet_created_at %></li>
  <li><%= tweets.tweet_id %></li>
  <li><%= tweets.tweet_source %></li>
  <li><%= tweets.tweet_text %></li>
  <li><%= tweets.user_id %></li>
  <li><%= tweets.user_name %></li>
  <li><%= tweets.user_sc_name %></li>
  <li><%= tweets.user_loc %></li>
  <li><%= tweets.user_img %></li>
  <li><%= tweets.longitude %></li>
  <li><%= tweets.latitude %></li>
  <li><%= tweets.place %></li>
  <li><%= tweets.country %></li>
<% end %>
</ul>

它没有路由到正确的页面。请帮帮我,我被这个困住了。

4

2 回答 2

0

-根据评论更新-

Tweetsblog2::Application.routes.draw do
    resources :coordinates
    get "tweets/show"  => "tweets#show"
    get "tweets/index" => "tweets#index"

删除资源 :tweets 应该可以解决您的问题并允许您使用只需调用 2 个选项。初始资源 :tweets 告诉 Rails 你想要资源丰富的路由(索引显示所有资源,显示指定的资源,等等)。因此,只需构建上述 2 条非资源丰富的路线听起来就像您想要的那样。我通常这样做的方式是将搜索表单包含在索引页面中,如果没有搜索参数,则显示所有推文。)

于 2013-07-19T15:19:58.250 回答
0

你必须写

resources :tweets, except: [:index,:show]

因为您首先声明了资源,所以 rails 尝试匹配其默认路由而不是您的自定义操作:

get "tweets/index"
于 2013-07-19T15:20:50.607 回答