参数双重发布ActiveSupport :: HashWithIndifferentAccess

时间:2012-12-01 08:54:00

标签: ruby-on-rails ruby-on-rails-3

似乎我的主题标签是通过错误的形式发送的,而不仅仅是#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 %>

1 个答案:

答案 0 :(得分:2)

您在类hashtag的对象的表单上有一个名为#content且值为Hashtag的字段,因此:

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