0

私のハッシュタグは #content として送信されているのではなく、間違ったフォームで送信されているようです {"hashtag"=>"#content"},

Parameters: {"utf8"=>"✓", "authenticity_token"=>"h4S3tOePv3+tUY3o10lc2uEHP92+s6oGhv727uEcR5A=", "hashtag"=>{"hashtag"=>"#content"}, "commit"=>"Submit!"}

コントローラ

class HashtagsController < ApplicationController

    def home 
        @hashtag = Hashtag.new(params[:hashtag])    
        @random_hashtags = Hashtag.order("RANDOM()").limit(4)
    end

    def create
    hash_search = params[:hashtag]
    Twitter.search("yahoo", :lang => "en", :count => 100, :result_type => "recent").results.map do |tweet|
        Hashtag.create!(
            tweet_id: tweet.id,
            text: tweet.text,
            profile_image_url: tweet.profile_image_url,
            from_user: tweet.from_user,
            created_at: tweet.created_at,
            hashtag: hash_search
        )   
        end
        redirect_to root_url
    end
end

<%= form_for(@hashtag) do |f| %>
                <div class="input-prepend input-append">
                <span class="add-on swag">#</span>

                <%= f.text_field :hashtag , class: "span3 inverse", id:"appendedPrependedInput" %>

                <%= f.submit "Swag!", class: "btn btn-inverse" %>
                <% end %>
4

1 に答える 1

2

クラス のオブジェクトのフォームに、hashtag値で呼び出されるフィールドがあるため、次のようになります。#contentHashtag

{ハッシュタグ(クラス): {ハッシュタグ(フィールド): '#コンテンツ'}}

于 2012-12-01T08:56:29.143 に答える