1

I've been searching with not much luck for this... I have the code

url = params[:url]; if url == "" @myString = "No URL specified, cannot continue" else =begin DO SOME STUFFS.... =end end 

But the DO SOME STUFFS is still getting called. I have my index page which I perform actions on the _GET variables. I'd like to load the index page without the parameters in the URL. How do I check if they are set - if they're not, then display a message. If they are, process the requests...

Thanks!

4 Answers 4

1

Try this:

url = params[:url]; if params[:url].nil? @myString = "No URL specified, cannot continue" else DO SOME STUFFS.... end 

When params[:url] is empty it's equal to nil, not "".

Sign up to request clarification or add additional context in comments.

1 Comment

when params is empty, it's equal nil not ""
1

use if url.blank?
blank? checks for nil and empty string and if you are not passing the url then accessing params[:url] would return nil. That is why your condition is failing.

Comments

1

rails 5:

@myString = "No URL specified, cannot continue" unless params[:url] 

Short and simple

Comments

0
url = params[:url] if url # do stuff else @my_string = "No URL specified, cannot continue" end 

params[:url] will be nil if not provided. nil evaluates false in a conditional.

2 Comments

it won't work if url is empty. You should use if url.blank? here.
Using if url = params[:url] would remove the awkward line at the top

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.