Ruby on rails 配置文件中的命名错误#显示未定义的方法"关于';零级:零级

Ruby on rails 配置文件中的命名错误#显示未定义的方法"关于';零级:零级,ruby-on-rails,Ruby On Rails,我目前正在重新设计我的路线,这导致我的Rails应用程序中出现很多错误。我来自这样的地方 users/:user_id/profiles/id/reviews 到 注册后,用户将被重定向(注册后重定向)到配置文件 /users/:user_id/profile/new 用户可以在其中填写表单(允许配置文件的嵌套属性) 单击“提交”后,这些数据将不会保存在任何位置。用户也不会被重定向到#show,因为my profiles controller显然存在一些问题。既不展示也不创作作品。这是控

我目前正在重新设计我的路线,这导致我的Rails应用程序中出现很多错误。我来自这样的地方

users/:user_id/profiles/id/reviews

注册后,用户将被重定向(注册后重定向)到配置文件

/users/:user_id/profile/new
用户可以在其中填写表单(允许配置文件的嵌套属性)


单击“提交”后,这些数据将不会保存在任何位置。用户也不会被重定向到#show,因为my profiles controller显然存在一些问题。既不展示也不创作作品。这是控制器

    class ProfilesController < ApplicationController
  before_action :set_profile, only: [:show, :edit, :update, :destroy]

  def show
    @profile = current_user.profile
    @review = Review.new
    Review.where(profile: @profile) 
  end

  def new
    @user = User.eager_load(:profile).find(params[:user_id])
    @profile = Profile.new
  end

  def edit
    @profile = @user.profile
  end

  def create
    @user = current_user
    @profile = current_user.build_profile(profile_params)

    respond_to do |format|
      if @profile.save
        format.html { redirect_to user_profile_path(current_user.id), notice: 'Profile was successfully created.' }
        format.json { render :show, status: :created, location: @profile }
      else
        format.html { render :new }
        format.json { render json: @profile.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @profile.update(profile_params)
        format.html { redirect_to user_profile_path(current_user.id), notice: 'Profile was successfully updated.' }
        format.json { render :show, status: :ok, location: @profile }
      else
        format.html { render :edit }
        format.json { render json: @profile.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /profiles/1
  # DELETE /profiles/1.json
  def destroy
    @profile.destroy
    respond_to do |format|
      format.html { redirect_to users_url, notice: 'Profile was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private

    def set_profile
      @profile = current_user.profile
    end

    def profile_params
      params.permit(:about, :avatar)
    end

    end
class ProfilesController
我真的需要帮助调整控制器,使其在没有配置文件id的情况下工作。以下是显示页面,以防万一:

<% if @profile == current_user.profile  %>
    <strong> Welcome </strong><%= current_user.first_name  %>
<% else  %>
    <strong> This is a profile of </strong><%= @profile.user.first_name  %> <%= @profile.user.last_name  %>
<% end  %>


<p>
  <strong>About:</strong>
  <%= @profile.about %>
</p>


    <strong>Profile image</strong>
    <%= image_tag(url_for(@profile.avatar), style: 'width:50px; height:50px;') %>
</p>

<%= render 'reviews/form' %>

<% @reviews.each do |review| %>
    <%= review.user.first_name %> <%= review.user.last_name %> wrote <small> <%= time_ago_in_words(review.created_at) %> ago </small>
    <p>
        <%= review.content %>
        <br>
        <strong> Rating </strong><%= review.rating %>
    </p>
<% end %>

<%= link_to 'Edit', edit_user_profile(current_user.profile) %>
<%= link_to 'Show other profiles', users_path %>


<div class="container">

欢迎
这是

关于:

配置文件图像

以前写的
评级

多谢各位。 另外,我试着使用ProfileController(单个),但这根本不起作用,因为应用程序找不到控制器

更新:
所以,我尝试使用表单,看起来表单既不会保存到个人资料也不会保存到用户。即使我去掉了嵌套属性,它仍然不会保存。这将保持未冷却状态…

因为我可以看到您正在为
使用
字段,\u,所以请检查在发布时发送的结构od参数。我想它们可能看起来像:

user: { :street, profile_attributes: { :about, :avatar } }
如果是,您需要更改允许的params方法以匹配实际发送的内容。 下一个建议是在用户模型中为:profile
添加
接受\u嵌套的\u属性\u,并通过保存用户之外的保存配置文件的方式为
使用
字段\u,因为当前代码有点凌乱(表单\u用于用户,带有指向配置文件控制器的配置文件字段)


如果您不想处理嵌套的属性,您也可以将表单重写为@profile…

您能否与我们共享创建操作日志项。当前的user.profile似乎为零,您是否可以确认这种情况?#ProfilesController的创建操作在代码中。或者你是说smth。否则呢?哦,事实上也许我是这样想的,因为用户应该能够看到其他用户的个人资料,“@profile=@user.profile”。但是这不起作用,您可能还想阅读更多关于嵌套表单的内容:我的编码经验非常短。你能具体说明一下,这是什么意思吗。我甚至不知道如何检查通过的参数。我去了浏览器,但我想这不是正确的方式做。。。谢谢,P.S。我已经有了这个:在启动rails的控制台中为配置文件接受嵌套的配置文件,在每个请求之后都有关于它的日志信息,例如路径、控制器、参数等。您可以在那里检查它,或者在这里发布完整的控制台输出启动后“/users/11/profile”对于::1在2019-11-27 06:11:07-0600由ProfilesController处理#创建为HTML参数:{“utf8”=>“✓", "真实性令牌“=>”一些令牌“,”用户“=>”{“街道”=>“st”},“档案”=>{“关于”=>“ab”,“化身”=>“original.jpg”},“提交”=>“保存您的档案”,“用户id”=>“11”}用户加载(0.1ms)选择“用户”。*从“用户”中选择“用户”。“id”=?按“用户”订购。“id”ASC限制?[[“id”,11],“限制”,1]]↳ app/controllers/profiles_controller.rb:21
<% if @profile == current_user.profile  %>
    <strong> Welcome </strong><%= current_user.first_name  %>
<% else  %>
    <strong> This is a profile of </strong><%= @profile.user.first_name  %> <%= @profile.user.last_name  %>
<% end  %>


<p>
  <strong>About:</strong>
  <%= @profile.about %>
</p>


    <strong>Profile image</strong>
    <%= image_tag(url_for(@profile.avatar), style: 'width:50px; height:50px;') %>
</p>

<%= render 'reviews/form' %>

<% @reviews.each do |review| %>
    <%= review.user.first_name %> <%= review.user.last_name %> wrote <small> <%= time_ago_in_words(review.created_at) %> ago </small>
    <p>
        <%= review.content %>
        <br>
        <strong> Rating </strong><%= review.rating %>
    </p>
<% end %>

<%= link_to 'Edit', edit_user_profile(current_user.profile) %>
<%= link_to 'Show other profiles', users_path %>


<div class="container">
user: { :street, profile_attributes: { :about, :avatar } }