I know this question has been asked several times, but there is one thing that I cannot follow. I am trying to move to the next user in my Kaminari pagination after a form is submitted. I have the code working where it will increment the page, but there's currently no conditional statement to keep it from stopping until the form has been submitted:
<%= f.submit "Submit Score", class: "btn btn-default" %>
<script type="text/javascript">
window.location.href="?page=<%=#users.current_page+1 %>"
</script>
Here I have my f.submit button and below it is the code that increments the counter. Right now, however, nothing is stopping the incrementing, so when I refresh the page, the counter scrolls until the last user has been reached. I have tried using hidden_tags and flags to add to the conditional if-statement, but nothing is working correctly. I just feel like there is a very simple solution, but I have been messing with my code for a couple hours now, so I am at a loss. Thank you in advance!
Related
On an index page I have a table with a bunch of listed items. Each <tr></tr> within the table's <tbody>not only lists each item, but also allows you to
update that item
click edit to take you to the edit screen for that item
Here is a picture:
Within development in safari: I can successfully update each listed item and it all works just fine. However: when running my feature spec with capybara and selenium-webkit (which uses firefox):
It appears that capybara finds the submit button ok and even clicks it
But then nothing happens. For some reason the form appears to not be submitting when that update button is clicked.
To make things even more strange: in development mode while testing with firefox, clicking the update button works sometimes. Sometimes it doesn't work and I have to refresh the page, and then it works.
I tried putting a binding.pry in right before clicking the Update abc button in order to manually click the button at that step. I noticed that clicking the button manually was not submitting the form either.
Here is my relevant spec:
scenario "within the index page", js: true do
select 'some selection', from 'item_1_jazz'
select '12345', from 'item_1_something'
# I attempted putting a binding.pry here, and noticed that clicking the update button still wasn't submitting the form
find("#update_some_item_1_btn").click
expect(page).to have_content 'The item was successfully updated.'
end
Update Here are my buttons within the form:
<td class="btn-group">
<%= f.submit 'Update abc', class: "btn btn-success btn-sm", id: "update_#{dom_id(item)}_btn" %>
<%= link_to edit_item_path(item), class: "btn btn-info btn-sm" do %>
<i class="fa fa-pencil"></i> Edit
<% end %>
</td>
Question: In firefox: Capybara appears to find the submit button just fine and even click it. But why isn't Capybara able to submit the form within Firefox? Also: why in development mode with firefox does the button only work sometimes? It appears something is stopping the form form from submitting.
Based on responses to comments on the OQ, it appears you have form elements wrapping your td elements inside a tr. That is invalid HTML since a form element is not a valid child of a tr, and different browsers may/do interpret markup like that differently. If you don't need IE compatibility then you can use the HTML5 form attribute to tie form elements outside a form back to the form you want them associated with, however if you do need IE compatibility you'll need to look at other solutions such as not using table/tr/td elements but possibly styling other types of elements with 'display: table/table-row/etc` or one form wrapping the whole table and determining which element to update based on the button clicked.
I am trying to figure out how can I use the button value from view to corresponding controller. I have three button which I have grouped them. Based on user selection, I want to do different functions (eg: List the task, form to add the tasks..etc). For that I want to pass the button value to the controller.
<div class="btn-group btn-group-justified">
Task Lists
Task Category
Add Task
</div>
I am not sure if there is better way to do this than button groups. I am not familiar with javascript also.
To make it clear, I have user information on the left side of the page which is already designed. These buttons are on the top of the right side of the page. Upon selecting the buttons, right side of the page should change/reloaded based on the selection.
You can try following
<div class="btn-group btn-group-justified">
Task Lists
Task Category
Add Task
</div>
You can use links to go to the controller action you want (if I understand your question correctly). You would use the paths/routes to the specific action you want. It would look something like this:
Task Lists
Or you can do it in rails direction, using the link_to method:
<%= link_to "Task Lists", tasks_lists_path, class: "btn btn-primary" %>
Again, this depends what the routes you are using are. If you want to pass parameters with the link, it gets a bit more complicated, but not much.
For more information: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
One option is triggering an ajax post request when the button is clicked and send the data to a particular controller action.
Could also just pass params through a link_to.
I am trying to create a button and on that button I have created a popup with angularjs. When I am using normal html tag it is opening the popup properly .But When I am converting in rails tag the popup gets dissapear within 1 sec and automatically the pages gets redirected to some other page .I have never use angularJs..Any solution will be helpful
<button type="button" class="btn btn-primary btn-lg" ng-click="deviceregisteration($event)">Add New Device</button>
So my this rails code is creating problem as I have mention above
<%= f.submit 'Add New Device',:class =>'btn btn-primary btn-lg' ,'ng-click'=>"deviceregisteration($event)" %>
The reason that your button made the popup disappeared is that it submitted the form.
Your plain HTML way, that button is simply a button, nothing more, so when you hit that button, it triggered the event.
When you used rails code, that button is a submit button, when you click on, it triggered the event and also submit the form and redirect to another page due to the response.
To fix this, you can just use f.button instead of f.submit.
Let me first state that this is an instance of using a lot of other peoples' code and not completely understanding what's going on and how to fix my issue.
I followed the Railscast for infinite scroll using will_paginate, and have that working fine.
I load 12 items per page, each in it's own partial. Each item is an object that a user can 'like' by clicking a 'thumbs up' button.
I ajax-ified this button, and reload the partial for the item that is 'liked'.
This works fine on items 1-12 (the first page).
When a user clicks the thumbs up button on an item that is loaded via infinite scroll, the ajax call executes, but doesn't find the object again, and the partial simply goes blank.
Here's my code-
##messages partial
<div class="span3 well" style="height:360px;" id="message-<%=message.id%>">
<div class="thumbnail">
<%= image_tag message.gif.url %>
<div class="caption">
<h5><%=link_to message.sender, "/profile/#{User.find_by_username(message.sender).id}"%></h5>
<h5><%=message.chain.subject %></h5>
<p><em>"<%= message.content %>"</em></p>
<p><a href="/upvote/<%=message.id%>" data-remote="true" class="btn btn-success"><%=message.up_votes%>
<i class="icon-thumbs-up"></i> Nice Work</a>
</div>
</div>
</div>
# js.coffee (from railscast)
jQuery ->
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text('Loading more gifs...')
$.getScript(url)
# vote.js -- js executed by ajax call
$("#message-<%=params[:id]%>").load(location.href+" #message-<%=params[:id]%>>*", "");
I'm pretty certain the problem is in the vote.js. the .load(location.href+" #message-<%=params[:id]%>>*", ""); seems to not be able to find the objects on the 2nd, 3rd, 4th, etc. pages because it uses location.href which, as the current url, only supplies the first 12 objects. I think I need to somehow put the page in that url, but I'm not sure how to accomplish that.
EDIT-
Alternatively, maybe I should have an endpoint for all messages that isn't paginated, and call that url instead of location.href + ?
This issue seems to have resolved itself.
It's funny it didn't seem to work locally, but is working on Heroku.
If anyone has an explanation for this I'd love to hear, but otherwise this is solved!
I am pretty new to Ruby on rails. I have one query
I have one view (say view1) in which I am showing a drop down. For that I have passed and array and populating the drop down using that array like dis
<td><=% select_tag, options_for_select(#businessApprovers)></td>
So when I submit the form it goes to an action which intrun renders another view which has 5 tabs in body and each tab has a partial view. one of them calls my previous view view1. Now when it calls the view1 it again shows the drop down. instead it should show only one value and that too non editable.
we are having some other drop down too but they have hard coded values. We are doing that like this:
<td><=% f.field :contries, :condition_select, [abc,pqr] ....
and above thing is working fine. For that it is not showing drop down.
So I wanted to know how to avoid that drop down. Also what is the use of "f.field" because I removed that and from then on it is causing this problem.
Firstly, field is for CSV, text_field is a thing. Is that what that should be? Also, I'm hoping that's not exact code.
Instead of:
<td><=% f...
It should be:
<td><%= f...
That aside, if you're simply looking to display a select field when no selection has yet been made and simply text when it DOES have a value, then it would be as simple as using a conditional:
<% if thing.something.empty? %>
<%= f.select ... %>
<% else %>
<%= thing.something %>
<% end %>
If my assumptions were incorrect, please reply and I'll revise.