DEV Community

Mary Webby
Mary Webby

Posted on

Photogram GUI (graphical user interface)

Difference in redirect_to in contrast to render

  • render() is only very beneficial in terms of when you are using it to display one piece of information per page. this means that everything in your action of your controller is really all the information that you need for the page.

  • in contrast to redirect_to(), this specific type of page rendering allows you to sort of push all the information you acquired in within your action and allow it to be placed into another page, with other info from other actions. This helps in very dynamic and info packed pages where you want multiple different sections doing different things but don't want it to all be in one controller. for example, when you are editing and adding new photos to a users page, but also want to display and post comments on the photos. You would have those 3 different actions, all redirecting to the same page.

Understanding what .where returns

when searching for a specific user within an action, you need to search within all the Users model, and then pick that id.

def show
    username = params.fetch("username")
    matching_users = User.where({ :username => username })
    @user = matching_users.at(0)

    render({ :template => "user_templates/user_details"})
  end 
Enter fullscreen mode Exit fullscreen mode

the specific line to note here is @user = matching_users.at(0)this is because we are returned a hash, and need to select the first position of for the specific user we want.

Top comments (0)