On Fri, Jul 10, 2015 at 9:06 PM, tamouse pontiki <tamouse.li...@gmail.com>
wrote:

>
>
> On Mon, Jul 6, 2015 at 2:09 PM, David Williams <li...@ruby-forum.com>
> wrote:
>>
>> Missing template users/follow, application/follow with {:locale=>[:en],
>> :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw,
>> :ruby, :coffee, :slim, :haml, :jbuilder]}. Searched in:
>>
>
> It cannot find a follow.html.erb template view.
>

Woops, clicked enter by mistake.

The error comes because it's looking for a file `follow.html.erb` in your
app/views/<controller>/ directory. In your `follow` method, you do not
direct it anywhere, or tell it to render any other view, so that's what
it's looking for. Did you want it to go somewhere else?

def follow
>     @user = User.friendly.find(params[:id])
>     if current_user
>       if current_user == @user
>         flash[:error] = 'You cannot follow yourself.'
>       else
>         current_user.follow(@user)
>         flash[:notice] = "You are now following #{@user.username}"
>       end
>     else
>       flash[:error] = "You must be logged in to follow
> #{@user.username}."
>       redirect_to :back
>     end
>   end


The only redirect in that method happens if there is no logged in user. The
rest of it sets the flash, then falls through to the standard render.

By convention, a controller action will render a template with the same
name as the action plus the format extension (html in this case) and
handlers.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t8%3Dx3ZJisaatS4H%2B3L4ih6qdcoBDg9We%3DA3aO%3Dds69C7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to