Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby On Rails - Retrieve data from text box a display its contents
    primarykey
    data
    text
    <p>I am new to Ruby on Rails. I have a simple application which connects to twitter. The application has a search text box on the home page and a submit button.Also there is a model and the controller for the same. I want to search some keywords dynamically on twitter and then display them on the home page of our application. I have created a text box and submit button in the "index.html.erb" page. I don't know how to take the keyword and pass into the controller. Then i want to display the result of the search. Can anyone site an example for the same ? Kindly suggest errors /changes in the code. like-this ruby on rails</p> <p><strong>The contents of the index.html.erb</strong> </p> <pre><code>&lt;h1&gt;Tweets about New Year Resolution&lt;/h1&gt; &lt;tr&gt;&lt;td&gt;Enter keyword &lt;input type = "text" name = "keyword"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input type = "submit" value = "SEARCH"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;%= form_tag(tweets/index, :method =&gt; "get") do %&gt; &lt;%= label_tag(:q, "Enter keyword :") %&gt; &lt;%= text_field_tag(:q) %&gt; &lt;%= submit_tag("SEARCH") %&gt; &lt;% end %&gt; &lt;div id="container"&gt; &lt;ul&gt; &lt;% @tweets.each do |tweet| %&gt; &lt;li class="&lt;%=cycle('odd', '')%&gt;"&gt; &lt;%= link_to tweet.from_user, "http://twitter.com/#{tweet.from_user}", :class =&gt; "username", :target =&gt; "_blank" %&gt; &lt;div class="tweet_text_area"&gt; &lt;div class="tweet_text"&gt; &lt;%=raw display_content_with_links(tweet.text) %&gt; &lt;/div&gt; &lt;div class="tweet_created_at"&gt; &lt;%= time_ago_in_words tweet.twitter_created_at %&gt; ago &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p><strong>The contents of the controller tweets.rb</strong></p> <pre><code>class TweetsController &lt; ApplicationController def index #Get the tweets (records) from the model Ordered by 'twitter_created_at' descending searchValue = params[:keyword] if Tweet.count &gt; 0 Tweet.delete_all end Tweet.get_latest_new_year_resolution_tweets("iphone") @tweets = Tweet.order("twitter_created_at desc") end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload