Skip to content

Instantly share code, notes, and snippets.

@MrJadaml
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrJadaml/8fe1cdc2dae37b48ca7e to your computer and use it in GitHub Desktop.
Save MrJadaml/8fe1cdc2dae37b48ca7e to your computer and use it in GitHub Desktop.
Form_Tag hell
# ------------------------------------> users_controller.rb <--------------------------------------------
class UsersController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
def edit
set_user
end
def update
set_user
if @user.update(user_params)
redirect_to @user, notice: "Profile was successfully updated"
else
render :edit
end
end
def claim_profile
@user = current_user
if @user.update(claim_params)
redirect_to users_path, notice: "Your profile claim has been sent successfully"
else
render :claim_profile
end
end
def claim_update
@user = current_user
if @user.update(claim_params)
redirect_to users_path, notice: "Your profile claim has been sent successfully"
else
render :claim_profile
end
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(
:first_name,
:last_name,
:email,
:password,
:twitter,
:instagram,
:avatar,
:avatar_cache,
:artist,
)
end
def claim_params
params.require(:user).permit(
:first_name,
:last_name,
:email,
:password,
:twitter,
:instagram,
:artist_approval,
:claim_id,
)
end
end
# ------------------------------------> routes.rb <-----------------------------------------------------
Rails.application.routes.draw do
root 'pages#home'
resources :murals, :users
get '/claim_profile/:id' => 'users#claim_profile', :as => 'claim_profile'
patch '/claim_profile/:id' => 'user#claim_update'
end
# ------------------------------------> form_tag <------------------------------------------------
= form_tag :claim_update, method: 'patch', html: {class: 'form-horizontal'} do
= hidden_field_tag :user @user
.form-group.col-md-offset-1
= label_tag :email, class: "col-md-1"
.col-md-9.col-md-offset-1
= email_field_tag :email, class: "form-control"
.form-group.col-md-offset-1
= label_tag :website, class: "col-md-1"
.col-md-9.col-md-offset-1
= text_field_tag :website, class: "form-control"
= hidden_field_tag :artist_approval, value: true
= hidden_field_tag :claim_id, value: @user.id
.action.col-md-offset-2
= submit_tag 'Claim Profile', class: "btn btn-primary"
@jeffdean-galvanize
Copy link

Try:

form_for @user, url: claim_profile_path(@user), method: :patch, html: {class: 'form-horizontal'} do |f|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment