Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 根据Rails中的另一个操作显示更新操作的不同通知消息_Ruby On Rails_Routes - Fatal编程技术网

Ruby on rails 根据Rails中的另一个操作显示更新操作的不同通知消息

Ruby on rails 根据Rails中的另一个操作显示更新操作的不同通知消息,ruby-on-rails,routes,Ruby On Rails,Routes,我正在做一个用户在船上显示一个表单,其中包含从Twitter提交和获取的数据,我使用相同的表单进行更新操作,但路径不同,如果用户提交表单,他将被引导到他的个人资料页面(对他的个人资料进行基本更新)。我只想为这一步添加一条不同的通知消息,因为它使用的是updateaction one,因此用户可以知道配置文件是创建的而不是更新的 users/finish\u signup.html.haml = simple_form_for(@user) do |f| = f.input_field :na

我正在做一个用户在船上显示一个表单,其中包含从Twitter提交和获取的数据,我使用相同的表单进行
更新
操作,但路径不同,如果用户提交表单,他将被引导到他的个人资料页面(对他的个人资料进行基本更新)。我只想为这一步添加一条不同的通知消息,因为它使用的是
update
action one,因此用户可以知道配置文件是创建的而不是更新的

users/finish\u signup.html.haml

= simple_form_for(@user) do |f|
  = f.input_field :name
  = f.submit t('go')
路线

get ':id', :to => "users#show"
get ':id/finish', :to => "users#finish_signup", :as => 'finish_signup'
完成注册方法

def finish_signup
    # ...
    # for example
    # redirect_to user_show_path_helper(@user), :notice => t('sucess_profile_created')
end
更新方法

def update
    @user = User.friendly.find(params[:id])
    @page_has_darker_background = true

    if @user.update(user_params)
      redirect_to user_show_path_helper(@user), :notice => t('sucess_profile_update')
    else
      render 'edit'
    end

end

谢谢

在执行
@user.update(user\u params)
之后,您将检查您的用户参数,并相应地设置通知消息。 例如,如果
params[:user][:first_name]
注意:
first name已更新或
参数[:user][:last\u name]
然后
注意:
last name更新,然后
重定向到user\u show\u path\u helper(@user)

,正如@gaurav建议的那样,我添加了一个隐藏字段,并根据它进行了验证

形式

更新

def update
    @user = User.friendly.find(params[:id])
    @page_has_darker_background = true

    if @user.update(user_params)
      redirect_to user_show_path_helper(@user), :notice => params['user']['finish_signup'] ? t('created') : t('update')
    else
      render 'edit'
    end
  end

我在这一步中使用相同的表单,在配置文件设置页面中也使用相同的表单,在这两个步骤中,数据已经存储。此步骤的目的是让用户检查他们的信息,然后被告知他们的配置文件已创建而未更新。(在幕后,他们实际上是在更新个人资料)但必须至少有一个字段是非公共的。。。使用该字段进行验证。我添加了一个隐藏字段,并基于该字段进行了验证。非常感谢:)
def update
    @user = User.friendly.find(params[:id])
    @page_has_darker_background = true

    if @user.update(user_params)
      redirect_to user_show_path_helper(@user), :notice => params['user']['finish_signup'] ? t('created') : t('update')
    else
      render 'edit'
    end
  end