I am using twitter gem with rails in order to retrive the user timeline and post an update:
def index
@tweets = Twitter.home_timeline
end
def tweet
text = params[:text]
Twitter.update(text) unless text = nil
end
The view which sends the request via jquery/ajax:
<input type="text" class="tweet-box" placeholder="tweet something" />
<input type="submit" class="tweet-button" value="tweet" />
<script type="text/javascript">
$(".tweet-button").on('click',function(e){
e.preventDefault();
$.post('/twitters/tweet', { text: $(".tweet-box").val() });
});
</script>
finally the routes:
get "twitters/index"
post "twitters/tweet"
getting the timeline works fine, however when trying to send the update, i get this error:
Missing required parameter: status
What is the problem?
Thanks
"unless text = nil"
This is setting text TO nil, so there is no text being passed into update()
A good habit is to always put the literal on the left:
nil == text
That way if you for get == and do = it will fail because you can't assign to a literal.
try either "unless text == nil" or "unless text.nil?"