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

您有一个名为hashtagvalue的字段#content,在 class 对象的表单上Hashtag,因此:

{hashtag(class): {hashtag(field): '#content'}}

于 2012-12-01T08:56:29.143 回答