1

Why does this not work :

params[:mobile].nil? ? redirect_to home_path : render nothing: true, status: 200 

Works in all other case ternary like :

if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this 

Can anybody see something I'm not seeing here?

0

1 Answer 1

6

Ruby is getting confused by the spaces . If you rewrite your method calls to use parentheses it will work:

params[:mobile].nil? ? redirect_to(home_path) : render(nothing: true, status: 200) 
Sign up to request clarification or add additional context in comments.

1 Comment

Or, just use the much more readable if/then/else instead of the obtuse conditional operator, which just so happens to have the correct precedence so that everything just works: if params[:mobile].nil? then redirect_to home_path else render nothing: true, status: 200 end

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.