开发者

Can't find View template in Rails?

开发者 https://www.devze.com 2023-01-26 16:37 出处:网络
This is my users_controller.rb code: ... def edit @user = @current_user end def update @user = @current_user # makes our views \"cleaner\" and more consistent

This is my users_controller.rb code:

  ...
  def edit
    @user = @current_user
  end

  def update
    @user = @current_user # makes our views "cleaner" and more consistent
    if @user.update_attributes(params[:user])
      flash[:notice] = "Account settings updated."
      redirect_back_or_default account_url
    else
      render :action => 'edit'
    end
  end
  ...

I have the following views/users:

  1. new.html.erb
  2. password.html.erb
  3. profile.html.erb
  4. show.html.erb

Everytime I try to update my user account settings, the following pops up:

ActionView::Missing开发者_StackOverflowTemplate (Missing template users/edit.erb in view path app/views:vendor/plugins/admin_data/app/views):
  app/controllers/users_controller.rb:46:in `update'

It's not the fault of admin_data is you are curious. It's the controller. What have I done wrong? Thanks.


First, if you want the update action to return to :show, you should change

render :action => 'edit'

to

render :action => 'show'

otherwise, it will of course look for edit.html.erb or edit.erb

Second, if you use 'show' for letting the user edit his/her information, why do you actually have the :edit action in your controller? If you don't use it, you should probably remove the following:

def edit
  @user = @current_user
end


unless you tell the edit method to render something else or redirect to some where, the default is that it will look for a template of edit.erb...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号