【发布时间】:2014-12-12 16:50:10
【问题描述】:
我是一名 Rails 初学者,在使用 best_in_place gem 时遇到了一些问题。我有一个带有显示视图的配置文件控制器,这里没什么复杂的:
class ProfileController < ApplicationController
before_action :get_user
def show
end
def edit
end
def update
if @user.update(user_params)
format.html { redirect_to show_profile_path(@user) }
else
format.html { render :edit }
end
end
private
def get_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:first_name, :last_name, :address, :lat, :lng, :telephone)
end
end
我希望我的用户能够直接从他们的个人资料页面编辑他们的个人资料。所以在我的个人资料#show 视图中我有这个字段:
<em> <%= best_in_place @user, :telephone, :type => :input %> </em><br>
问题是当我尝试加载显示配置文件页面时出现此错误:
undefined method `user_path' for #<#<Class:0x00000002d04880>:0x00000008f85b30>
我不知道我应该如何在我的路线中使用 best_in_place 和配置文件资源。这是我的个人资料资源的 rake 路线:
profile_index GET /profile(.:format) profile#index
POST /profile(.:format) profile#create
new_profile GET /profile/new(.:format) profile#new
edit_profile GET /profile/:id/edit(.:format) profile#edit
profile GET /profile/:id(.:format) profile#show
PATCH /profile/:id(.:format) profile#update
PUT /profile/:id(.:format) profile#update
DELETE /profile/:id(.:format) profile#destroy
提前感谢您的回答!
更新:
我认为 best_in_place 会尝试访问 user_path,因此我尝试将 <%= best_in_place @user, :telephone, :type => :input %> 更改为:
<%= best_in_place profile_path(@user), :telephone, :type => :input %> 但现在我收到以下错误:
undefined method `telephone' for "/profile/1":String`
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 devise best-in-place