似乎我的主题标签是通过错误的形式发送的,而不仅仅是#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 %>
答案 0 :(得分:2)
您在类hashtag
的对象的表单上有一个名为#content
且值为Hashtag
的字段,因此:
{hashtag(class):{hashtag(field):'#content'}}