0

<%= form_tag(hashtags_path, :method => :vote) do %>カスタムメソッドを呼び出すために使用しようとしてdef voteいますが、途中で動作しているようです。最初に を呼び出しdef create、次に を呼び出しますdef vote。この時点で多くの不要なアクションがトリガーされるため、最初に作成を実行したくありません。

ハッシュタグコントローラー

class HashtagsController < ApplicationController

    def home 

    end

    def vote
        redirect_to thanks_path
    end

    def show


    end

    def index

    end

    def create 
        Hashtag.pull_hashtag(params[:hashtag])
        @random_hashtag_pull = Hashtag.random_hashtags_pull
        respond_to do |format|
        format.html { redirect_to vote_path }
        format.js
    end
     end

end

_vote_tweets.html.erb

<%= form_tag(hashtags_path, :method => :vote) do %>
<div id="hashtags" class="twitter-hashtag-voting-block-v1">
    <% @random_hashtag_pull.each do |hashtag| %>
    <div class="span4 twitter-spans-v1" id="<%= hashtag.id %>">
    <div id="tweet-block-v1" class="hashtag-tweet-database-container">
    <div class="tweet-block-border-v1">
    <div class="tweet-block-spacing-v1">
        <div class="twitter-block-author-v1">
            <a class="twitter-block-user-v1" target="_blank" href="https://twitter.com/<%= hashtag.from_user %>">
            <span class="twitter-author-image-v1"><img alt="" class="twitter-author-image-photo-v1" src="<%= hashtag.profile_image_url %>"></span>
            <span class="twitter-author-name-v1"><%= hashtag.from_user_name %></span>
            <span class="twitter-author-nickname-v1">@<%= hashtag.from_user %></span></a>
            <iframe class="twitter-follow-button-v1" scrolling="no" frameborder="0" src="//platform.twitter.com/widgets/follow_button.html#align=right&button=grey&screen_name=<%= hashtag.from_user %>&show_count=false&show_screen_name=false&lang=en" allowtransparency="true"></iframe>
        </div>
    <div class="twitter-text-container-v1">
        <p class="twitter-text-field-v1"><%= sanitize(auto_link(hashtag.text).html_safe, :suppress_no_follow => true) %></p>
    </div>
    <div class="twitter-footer-v1">
        <a class="twitter-view-details-v1" target="_blank"  href="https://twitter.com/<%= hashtag.from_user %>/statuses/<%= hashtag.tweet_id %>">
        <span class="tweet-date-v1"><%= hashtag.created_at.strftime("%d %b %Y") %></span></a>
        <span class="twitter-vote-button-v1"><%= submit_tag "Vote!", class: "btn btn-mini btn-primary" %></span>
        <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
        <ul class="twitter-intent-ul-v1">
        <li class="twitter-intent-li-v1"><a href="https://twitter.com/intent/tweet?in_reply_to=<%= hashtag.tweet_id %>" class="twitter-intent-tweet" title="Reply"></a></li>
        <li class="twitter-intent-li-v1"><a href="https://twitter.com/intent/retweet?tweet_id=<%= hashtag.tweet_id %>"  class="twitter-intent-retweet" title="Retweet"></a></li>
        <li class="twitter-intent-li-v1"><a href="https://twitter.com/intent/favorite?tweet_id=<%= hashtag.tweet_id %>"  class="twitter-intent-favorite" title="Favorite"></a></li>
        </ul>
        </div>
        </div>
        </div>
        </div>
        </div>
    <% end %>
</div>
<% end %>

ルート.rb

root :to => "hashtags#home"
  resources :hashtags do
    get 'vote', :on => :member
  end

  match '/vote', :to => 'hashtags#vote'

  match '/thanks', :to => 'pages#thanks'
4

1 に答える 1

0

カスタムルートを作成する必要がありました

match '/cast_vote', :to => 'hashtags#cast_vote'

于 2012-12-16T01:55:46.553 に答える