0

Here's my controller method

def check @added_word = Word.where(:word => params[:word][:word]).first respond_to do |format| format.js end end 

In the view I have the following code:

 $("#added_words").append("<%= @added_word.word %>, "); 

How should i change the controller in order not to render the view if no record found ( false returned)?

1 Answer 1

1

Not very idiomatic, but it answers your question.

def check @added_word = Word.where(:word => params[:word][:word]).first if @added_word.present? respond_to {|f| f.js} else render :text => '' # or whatever end end 
Sign up to request clarification or add additional context in comments.

1 Comment

You could also do: render :nothing => true

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.