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 アプリには、 と という名前の 2 つのテーブルがCoordinatesありTweetsます。レンダリングするアクションが 4 つあります。

私の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/indextweets/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

あなたは書く必要があります

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

リソースを最初に宣言したため、レールはカスタムアクションではなくデフォルトのルーティングに一致させようとしています:

get "tweets/index"
于 2013-07-19T15:20:50.607 に答える
0

-コメントごとに更新-

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

リソース :tweets を削除すると問題が解決し、2 つのオプションを呼び出すだけで使用できるようになります。最初の resources :tweets は、リソースに富んだルートが必要であることを Rails に伝えます (インデックスはすべてのリソースを表示し、特定のリソースを表示するなど)。したがって、上記のようにリソースのない 2 つのルートを構築するだけで、あなたが望むように聞こえます。私が通常このようなことを行う方法は、インデックス ページに検索フォームを含めるだけで、検索パラメーターがない場合はすべてのツイートを表示することです。)

于 2013-07-19T15:19:58.250 に答える