-
-
Save maier-stefan/c4a34e47fdd055d3170f to your computer and use it in GitHub Desktop.
looking for a saver way then hidden fields
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
<h3>Lets do a reservation </h3> | |
<% unless current_user.blank? %> | |
<%= form_for @reservation, :url => make_a_booking_path, :html => { :class => 'form-horizontal' } do |f| %> | |
<% if @reservation.errors.any? %> | |
<div id="errorExplanation"> | |
<h2><%= pluralize(@reservation.errors.count, "error") %> prohibited this reservation from being saved:</h2> | |
<ul> | |
<% @reservation.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<%= f.hidden_field :event_id, value: @event.id %> | |
<%= f.hidden_field :user_id, value: current_user.id %> | |
<div class="form-group"> | |
<%= f.label :note, :class => 'control-label' %><div class="controls"> | |
<%= f.text_field :note, :class => 'form-control' %> | |
</div> | |
</div> | |
<%= f.submit "save", :class => 'btn btn-primary' %> | |
<% end %><!--end form for booking --> | |
<% else %> | |
<p> | |
Please log in to make a reservation! | |
</p> | |
<%= form_for(:user, :url => session_path(:user)) do |f| %> | |
<%= f.text_field :email %> | |
<%= f.password_field :password %> | |
<%= f.check_box :remember_me %> | |
<%= f.label :remember_me %> | |
<%= f.submit 'Sign in' %> | |
<%= link_to "Forgot your password?", new_password_path(:user) %> | |
<% end %> | |
<% end %> <!-- end reservation --> | |
<%= debug @reservation %> |
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
class PagesController < ApplicationController | |
def clubs | |
@clubs = Club.all | |
end | |
def club | |
@club = Club.find(params[:id]) | |
end | |
def events | |
@events = Event.all | |
end | |
def event | |
@event = Event.find(params[:id]) | |
@reservation = Reservation.new() | |
end | |
def make_a_booking | |
@reservation = Reservation.new(reservation_params) | |
respond_to do |format| | |
if @reservation.save | |
format.html {redirect_to :back, notice: "Reservation was successfully created."} | |
else | |
format.html {redirect_to :back, alert: "Something went wrong. Your Reservation was not successfully created."} | |
end | |
end | |
end | |
def index | |
end | |
private | |
def reservation_params | |
params.require(:reservation).permit(:user_id, :event_id, :note ) | |
end | |
end |
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
if I do | |
def event | |
@event = Event.find(params[:id]) | |
@reservation = Reservation.new(user_id: current_user.id, event_id: @event.id) | |
end | |
and no hidden fields then the params are shown in debug, but when it comes to save the params are gone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment