I have comments for my gossips and i display them in the show of my gossips.
When I clic on edit for my gossip that open new windows and that display me the actual title and content.
But when I clic on edit for my comment that open the view for edit bur the content is blank. How display the actual content when i want edit him.
View - edit comment :
<%= form_for edit_gossip_comment_path do |f| %>
<div class="form-group new-gossip-field">
<%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
</div>
<div class="form-group margin-left-50">
<button class="btn btn-primary" type="submit">Edit Comment</button>
</div>
<% end %>
View - edit gossip :
<%= form_for #gossip do |f| %>
<div class="form-group new-gossip-field">
<%= f.text_field :title, placeholder: "Title", class: 'form-control' %>
</div>
<div class="form-group new-gossip-field">
<%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
</div>
<div class="form-group margin-left-50">
<button class="btn btn-primary" type="submit">Edit Gossip</button>
</div>
<% end %>
If i try to let #comment instead edit_gossip_comment_path that would not work, I dont really understand why.
If you need see more code tell me.
I think that the problem is in your form of edit comment, you are not passing the comment, so you should pass the object of work for the form, like:
View - edit comment :
<%= form_for #comment, url: edit_gossip_comment_path(#comment) do |f| %>
<div class="form-group new-gossip-field">
<%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
</div>
<div class="form-group margin-left-50">
<button class="btn btn-primary" type="submit">Edit Comment</button>
</div>
<% end %>
with that, i belieave that the content of your comment will be show in the form.
Related
I need to add a button that persists the data of the following form but that when pressing it resets the view and stays in it, without redirecting to the index of the controller, I have tried an ajax call but I don't know why it didn't work for me.
How can I give a solution and add the button to save and continue?
<%= turbo_frame_tag dom_id(taxonomy) do %>
<%= form_with(model: [:admin, taxonomy], id: dom_id(taxonomy)) do |form| %>
<div class="box">
<div class="field is-horizontal">
<div class="field-body">
<div class="field">
<div class="control is-expanded is-relative">
<%= form.text_field :name, placeholder: true, class: "input mt-5" %>
<%= form.label :name, class: "label-hidden required" %>
</div>
</div>
<div class="field is-narrow">
<div class="control mt-5">
<%= form.submit nil, class: "button is-primary" %>
<%= link_to "#{ t '.cancel'}", admin_taxonomies_path, class: "button is-light" %>
</div>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
You need to add a target="_top" attribute to the frame: turbo_frame_tag dom_id(taxonomy), target: :_top
Otherwise Turbo tries to replace the current frame containing the form.
You can also just add data-turbo="false" on your link and the redirection will be working fine.
More info here in the documentation
https://turbo.hotwired.dev/handbook/drive#disabling-turbo-drive-on-specific-links-or-forms
One of my tests is creating a form post via javascript that is dropping the first input field from the form. The tests are obviously failing because of this. When deugging via binding.pry, it looks like a js post is dropping the first parameter [address_by_user] when posting it to my route. This parameter is posted just fine when testing via the ui in localhost but no longer works with rspec. Any idea what could cause this? Tests were passing as of two days ago and the forms haven't been changed. I tried restarting my computer in case it was a zombie process or something being cached, but the behavior continues. Any thoughts?
The form that is submitted via javascript using the following code:
var form_id = "#form-step" + currentIndex;
var my_form = $(form_id);
var url = $(form_id).attr('action');
var form_data = my_form.serialize();
console.log(form_data);
var submission = $.post(url, form_data);
The form looks like this and is submitted after clicking the "Next" button in a wizard, that works fine.
<%= form_with(url:"add_property", scope: :property, class: "form", id:"form-step0") do |f| %>
<div class="form-body" id="step0form">
<h4 class="form-section"><i class="ft-location"></i> <%= t(:property_details) %></h4>
<%= render 'shared/error_messages', object: f.object %>
<div class="row">
<div class="form-group pac-card col-md-8 offset-md-1 required" id='pac-card'>
<div class="field" id='pac-container'>
<%= f.label :address_by_user, t(:address), class:"label-control" %>
<%= f.text_field :address_by_user, :required => true, class: "form-control pac-input google-autocomplete", id:"pac-input" %>
</div>
</div>
<div class="form-group form-row col-md-2">
<div class="field">
<%= f.label :unit_number %>
<%= f.text_field :unit_number, class: "form-control" %>
</div>
</div>
</div>
<div class="form-group form-row">
<div class="field col-md-2 offset-md-1">
<%= f.label :bedrooms %>
<%= f.number_field :bedrooms, :required => true, class: "form-control", in: 1...20 %>
</div>
<div class="field col-md-2 offset-md-1">
<%= f.label :bathrooms %>
<%= f.number_field :bathrooms, class: "form-control", in:1...10 %>
</div>
<div class="field col-md-2 offset-md-1">
<%= f.label :accommodates %>
<%= f.number_field :accommodates, class: "form-control", min: "0" %>
</div>
</div>
<div class="form-group form-row">
<div class="field col-md-2 offset-md-1"><%=label_tag(t(:property_type))%></div>
</div>
<div class="form-group form-row" data-toggle="buttons">
<div class="btn-group col-md-12">
<div class="field col-md-2 offset-md-1">
<%= f.label :room_type, class: 'text-center btn btn-default active' do %>
<%= image_tag('house-icon.png') %>
<br>
<%= f.radio_button :room_type, "entire_place", checked: true %>
<span>Entire Place</span>
<% end %>
</div>
<div class="field col-md-2 offset-md-1">
<%= f.label :room_type, class: 'text-center btn btn-default' do %>
<%= image_tag('room.png') %>
</br>
<%= f.radio_button :room_type, "private_room" %>
<span>Private Room</span>
<% end %>
</div>
<div class="field col-md-2 offset-md-1">
<%= f.label :room_type, class: 'text-center btn btn-default' do %>
<%= image_tag('people.png') %>
</br>
<%= f.radio_button :room_type, "shared_room" %>
<span>Shared Room</span>
<% end %>
</div>
</div>
</div>
<div id="hidden-fields">
<%= f.hidden_field(:latitude, id: 'latitude') %>
<%= f.hidden_field(:longitude, id: 'longitude') %>
<%= f.hidden_field(:street_number, id: 'street_number') %>
<%= f.hidden_field(:street_name, id: 'route') %>
<%= f.hidden_field(:city, id: 'locality')%>
<%= f.hidden_field(:state, id: 'administrative_area_level_1') %>
<%= f.hidden_field(:country, id: 'country')%>
</div>
</div>
<% end %>
When tested directly from the site via localhost, all parameters post fine and I get this: (as expected)
<ActionController::Parameters {"address_by_user"=>"Pura Uvita Vacation Home, Puntarenas Province, Uvita, Costa Rica", "unit_number"=>"", "bedrooms"=>"2", "bathrooms"=>"2.0", "accommodates"=>"6", "room_type"=>"entire_place", "latitude"=>"9.1839769", "longitude"=>"-83.72444630000001", "street_number"=>"", "street_name"=>"", "city"=>"Uvita", "state"=>"Provincia de Puntarenas", "country"=>"Costa Rica"} permitted: false>
When the parameters are obtained via binding.pry from the rspec flow, the following is the result:
<ActionController::Parameters {"unit_number"=>"", "bedrooms"=>"2", "bathrooms"=>"2", "accommodates"=>"6", "room_type"=>"entire_place", "latitude"=>"", "longitude"=>"", "street_number"=>"", "street_name"=>"", "city"=>"", "state"=>"", "country"=>""} permitted: false>
The two most likely causes of this are
The fields are no longer actually being filled in - look at the browser while the tests are running and see if the form is actually being correctly filled in.
You have an error in another JS file causing the JS you think is processing the form not to run. This can happen because JS assets are concatenated in the test environment, allowing an error in on JS file to prevent any files concatenated after it not to be processed.
I am trying to initiate a variable showName when the page loads. It worked fine when I did it using just angular but when I implemented it with rails(with embedded ruby tags) I am not able to hide the text field and save button as my variable gets undefined. I have tried couple of ways and ended with no result.
Here is my code. Any help is really appreciated. Thanks.
Edit.html.erb:
<div class="row" ng-controller="EditUserCtrl">
<div class="col-md-6 col-md-offset-3" id="editForm">
<%= form_for(#user) do |f| %>
<h1 id="editHeader">Account Information </h1>
<%= render 'shared/error_messages' %>
<div class="form-group">
<%= f.label :name, "Full Name:" %><br>
<div class="row">
<div class="col-sm-7">
<div ng-hide="showName">
<%= f.label :name, #user.name , id:"editFields" %>
</div>
<%= f.text_field :name, { :'ng-show' => 'showName'}%>
</div>
<div class="col-sm-5" ng-show="showName">
<%= f.button "Save", :action => "update_name" , :method => :put, class: "btn btn-primary", :'ng-click' => "clicked()", id:"editAccount" %>
</div>
<div class="col-sm-5" ng-hide="showName">
<i id="nav-cart-count" class="glyphicon glyphicon-edit"></i> Edit
</div>
</div>
</div>
<% end %>
</div>
Use ng-init to initialize the variable
<div class="row" ng-controller="EditUserCtrl" ng-init="showName = true">
Ruby 2.1.5 on Rails 4.2.0:
I have two directories. One directory is a rails-generate scaffold named 'inqueries'. The other directory is named 'welcome', which only houses a landing paged named index.html.erb. The inquery form works & submits fine as long as I'm using the view from the actual 'inquery' scaffold/directory.
I am able to render the inquery _form on my index.html.erb landing page using :
<%= render partial: "inqueries/form", locals: {inquery: #Inquery} %>
However, this JUST renders the form. When I hit the submit button, no errors, flash messages, or inquery is submitted. It is complete non-action, including on my rails terminal.
How can I properly make the form work on my landing page?
Here is my welcome_controller.rb file. This controller handles the landing page where I am trying to render the inquery scaffold's form:
class WelcomeController < ApplicationController
def index
#inquery = Inquery.new
render layout: false
end
end
This is my new rails scaffold-generated method in the inqueries_controller.rb:
def new
#inquery = Inquery.new
respond_with(#inquery)
end
Sorry, Here is the Inquery _form itself:
<%= form_for(#inquery) do |f| %>
<div class="form-group col-lg-4">
<%= f.label t('.name') %><br>
<%= f.text_field :name, class: "form-control" %>
</div>
<div class="form-group col-lg-4">
<%= f.label t('.email') %><br>
<%= f.text_field :email, class: "form-control" %>
</div>
<div class="form-group col-lg-4">
<%= f.label t('.phone') %><br>
<%= f.text_field :phone, class: "form-control" %>
</div>
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<%= f.label t('.message') %><br>
<%= f.text_area :message, rows: 8, class: "form-control"%>
</div>
<%= f.submit t('.submit'), class: "btn btn-primary" %>
<% end %>
EDIT 2: I saw there were a couple of suggestions with the logic. I have simplified the partial just to see if I could get it to work and it still does not submit properly outside of its directory. I am new to rails, do I need to render a new action in the second directory that I am calling it into?
Your partial has 2 forms. The one which submits to inqueries#create is an empty form with no submit button, the other which has no action contains the text fields and the submit action.
The form_for tag will create the html tags, you dont need to specify them again.
Tip - Switch to haml. You won't ever look back at erb :)
This should work (not tested) -
<%= form_for(#inquery) do |f| %>
<div id="error_explanation">
<% if #inquery.errors.any? %>
<h2>
<%= pluralize(#inquery.errors.count, "error") %> prohibited this inquery from being saved:
</h2>
<ul>
<% #inquery.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
</div>
<br />
<div class="col-lg-12">
<div class="form-group col-lg-4">
<%= f.label t('.name') %><br>
<%= f.text_field :name, class: "form-control" %>
</div>
<div class="form-group col-lg-4">
<%= f.label t('.email') %><br>
<%= f.text_field :email, class: "form-control" %>
</div>
<div class="form-group col-lg-4">
<%= f.label t('.phone') %><br>
<%= f.text_field :phone, class: "form-control" %>
</div>
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<%= f.label t('.message') %><br>
<%= f.text_area :message, rows: 8, class: "form-control"%>
</div>
<div class="form-group col-lg-12">
<input type="hidden" name="save" value="contact">
<%= f.submit t('.submit'), class: "btn btn-primary" %>
</div>
</div>
<% end %>
Figured it out. Foolish error,
My welcome page is a bootstrap theme that I hadn't fully gone over. I had imported some unnecessary javascript files that I think were blocking the form.
In BootStrap, I can use the following code to get a button with an icon.
<button class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span> Click Me</button>
Now I want to do the same thing for the submit button of a Rails form. I don't know how to do it and below is my code:
<h1>Create a post</h1>
<%= form_for :post, url: posts_path do |f| %>
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, class: "form-control" %>
<p class="help-block">Please type the title of the post</>
</div>
<div class="form-group">
<%= f.label :body %>
<%= f.text_area :body, class: "form-control", rows: 5 %>
<p class="help-block">Please type the body of the post</>
</div>
<%= f.submit class: "btn btn-primary" %>
<% end %>
Could someone give me any suggestions?
I found the solution here: HTML code inside buttons with simple_form
<%= button_tag(type: 'submit', class: "btn btn-primary") do %>
Text
<% end %>