Last active
August 29, 2015 14:11
-
-
Save MrJadaml/8fe1cdc2dae37b48ca7e to your computer and use it in GitHub Desktop.
Form_Tag hell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------> 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try: